Hi,

how do I post the (eg) 5 most recent posted nodes on the frontpage?

I put in page.tpl.php something like this:

<?php if($is_front):
  
  $listlength="5";
  $content_type = 'image';

  $result1 = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n  WHERE n.type = '$content_type' AND n.status = 1 ORDER BY n.created DESC"), $listlength);
    
  while ($node = db_fetch_object($result1)) {
      $output .= node_view(node_load(array('nid' => $node->nid)), 1);
  }

  print $output;
<?php endif; ?>

It's an oversimplified version of a snippet I found elsewhere on this site. This works fine, but I still get the welcome page from drupal below my postings. So how can I get rid of that?

To see what I mean: http://sandbox.bumblebee.be

Thanks,

Chris

Comments

Dublin Drupaller’s picture

HI Chris,

Follow these steps.

  1. takethe snippet out of your page.tpl.php file
  2. go to CREATE -> CONTENT
  3. paste your snippet into the main body
  4. select PHP CODE as the INPUT FORMAT
  5. Under PUBLISHING OPTIONS deselect PROMOTE TO FRONT PAGE
  6. Under COMMENT Settings deselect add comments
  7. SUBMIT page
  8. make a note of the NODE ID. e.g. www.example.com/node/1 where '1' = the node ID
  9. go to ADMINISTER -> SETTINGS
  10. in the field for DEFAULT FRONT PAGE, set it to be node/n where n= node ID
  11. SAVE CONFIGURATION

Now when you go to the front page of your site, that node list page will be picked up and since you have now added a node to your site, the "welcome to your drupal site" message will dissapear.

hope that makes sense

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

drupaceous’s picture

Wow, that was indeed quick! :-) Makes perfect sense too. Thanks a lot!

publishing’s picture

Hello Dub & Drupal Nation,

Have a question which I believe to be simple, but I am wrecking my brain over it.

We would like the current content of our page.tpl.php to be both our front and home page (display @ www.examplesite.com). We have been of the understanding that page.tpl.php should be the default page layout for all pages, unless, there were some custom overrides in place which there are not.

We currently have "node" input in the default front page field of General Setting. This provides a listing of all nodes promoted to the front page, but not our desired page layout as depicted in page.tpl.php.

1) how do we get the contents of our page.tpl.php to display as our front page?

2) what should we input in the default front page field of General Settings so that the contents of our page.tpl.php displays?

Thank u for your time and interest. It is appreciated very much.....

reed.r’s picture

Another easy way is to install the Views module and filter the front page to show some impossible node for example:

display
filter: title - is equal to = "sdfksjdfhsefuywetowietpwetjk"

/M