By zanlus on
Here's my task: I want to put the titles from the nodes that are published to the front page into a div in the #content-inner portion of my front page that I am creating using the front_page module. I thought that I could surely take the line print $content and it would pull in the same content. I was clearly wrong.
Please point me in the right direction. I'm trying to learn php, but this project needs to get done before I have any level of mastery.
Thanks!
Ross
Comments
Views
I would recommend Views for this... pretty simple to make a View that displays x number of the latest nodes with the Promoted to front page flag. Views 2 is at release candidate stage, so it is likely stable enough for a live site (though keep an eye on it). You can then set that View (as a block) to display inside a custom region called "frontpage" or something, and print that region in your front page's code... or even skip the region/block part and directly embed the View itself into the front page.
Here's my guide on creating a custom front page (focus of the lesson is on using Views, Panels, etc... however there are a lot of tips on other ways):
http://drupal.org/node/278181#comment-910575
This goes into more detail on setting up a region to use on your home page: http://drupal.org/node/65064
Right, the $content variable is not what you need - that is the main line that brings in "all" the main content to the page, different on every page.
-- David
absolutecross.com
view module overhead..
The views.module is very good, but, it I find it introduces a large memory overhead I notice that it slows a site down quite a lot. If you don't already have views installed for other aspects of the site....the snippet you're looking for is this (copied from the front page.module readme.txt)
You can check at api.drupal.org if the
node_page_default();function has changed for the Drupal version you're using. the above is copied from the read me for the front page.module (version 5.x)hope that helps
Views performance
Cool I didn't know there was that code in the readme or I would have mentioned it also.
I'm not sure I'd characterize Views as using "a lot" of memory, or slowing the site down quite a lot, though I'm not an expert with that. I ran Devel tests with Views 1 on Drupal 5 (and Views sub-modules) both on and completely off and noted for the Drupal home page (running eAccelerator by the way... which of course an actual site should) average results of:
Views off:
Page execution time was 213.27 ms
* Memory used at devel_init(): 5.18 MB
* Memory used at devel_shutdown(): 6.53 MB
Views on:
Page execution time was 234.53 ms
* Memory used at devel_init(): 6.33 MB
* Memory used at devel_shutdown(): 8.33 MB
Definitely a difference, but not a speed decrease I could perceive without the aid of Devel. Looks like 1-2MB more RAM consumed as well (per user I assume). Visiting the stock Views "frontpage" view took an average of 240ms and about the exact same RAM.
So yeah, if you don't need Views don't use Views :) If you do have use for it, I don't think the performance is anything to worry about in light of the functionality you gain. The site I tested on is littered with random modules installed for testing, and has no performance optimizations, so I expect you'd get better numbers on an actual site (especially with proper caching).
-- David
absolutecross.com
Thanks!
Thanks to both of you! I like the idea of trying to avoid views, if only to avoid overhead, but I may start with views, as it seems simple and I already have it installed.
Ross
views isn't that bad..
HI Ross,
Don't get me wrong...views isn't that bad. but we've noticed it does add quite a lot of waiting time to render a fairly simple views generated page and the overall site performance.
Like the other poster said...it's not a massive overhead..it's only a few seconds...and is probably something you can ignore for sites that aren't busy or don't plan to be busy.
I find views.module very useful for prototyping ..i.e. build the view I want and once I'm happy, convert that to a PHP snippet that creates that view. Unless you're using all the features in views...which is unlikely in most circumstances..that's not a bad way to go. If the client wants to change the view output...fine...simply repeat the process.
The principle is really simple..i.e. the less modules you use, the faster your site will perform and the easier it will be to upgrade. The down side is that you need a bit of knowledge of php to be able to export a VIEW and convert it to a snippet.