because front page has no arg(1) (node id) I cannot load promoted node[s] in page.tpl.php . all I want to do is print something in one part of front page if a specific content type node in about to load in node.tpl.php. I search it alot but find no answer.


You mean a custom function?

I did a lot of this for a current project where we needed short little lists of nodes with different criterion all over. I found Views bulky and overkill in some places, so I added small functions to template.php. They're really just simple SQL SELECT statements.

For example:

function home_channel_list($title, $tids, $limit){

    $query = "SELECT t1.nid, MAX(t1.vid), t1.title, UNIX_TIMESTAMP(t2.field_pubdate_value) AS pubdate
                FROM {node} t1
                    JOIN field_revision_field_pubdate t2 ON t1.nid = t2.entity_id AND t1.vid = t2.revision_id
                    JOIN field_revision_field_channel t3 ON t1.nid = t3.entity_id AND t1.vid = t3.revision_id
                WHERE t3.field_channel_tid IN(".$tids.")
                    GROUP BY t1.nid ORDER BY pubdate DESC LIMIT ".$limit."";

        $result = db_query($query); 

        // Container div and title
        print '<div class="home-channel-block"><h2>'.$title.'</h2>';

        // Article list
        foreach ($result as $record) {
            $mypubdate = format_date($record->pubdate, 'custom', 'F j, Y, g:iA');
            print '<div class="home-channel-title"><a href="?q=node/'.$record->nid.'">'.$record->title.'</a></div>';
            print '<div class="home-channel-pubdate pubdate">'.$mypubdate.'</div>';         

        // Clear and close the container div
        print '<div class="myclear"></div></div>';
  • 1
    yes I think sql solution in the only option in my specific needs, thank u.
    – sepehr
    Aug 10 '11 at 10:14

Not 100% sure I understand - but I would create a block either from a view or with a custom function that pulls a list of articles where node_revision.promote = 1. Then just have it display on the front page only.

  • 1
    what I want to achieve is just cheking in page.tpl.php file that a specific content type node will be later load in node.tpl.php or not , either by user viewing node/nid or front page (in front page case by promoting node[s] of that specific content type). in former case it is easy like bellow:
    – sepehr
    Aug 3 '11 at 15:21
  • 1
    ` if (arg(0) == 'node') { $node = node_load(array('nid' => arg(1))); if (($node->type == 'slideshow') { //do some stuff } } ` I can check that current page is front or not but problem is that I am not sure promoted node will be that specific content type that I need. your second suggestion seems interesting , can you explain how I implement it? tnx.
    – sepehr
    Aug 3 '11 at 15:26

have a look at node_page_default() in modules/node/node.module and it's output, but I think its better to use another page.tpl.php for those content type via suggesting new .tpl files to theme layer via this function in template.php:

function mytheme_preprocess_page(&$variables) {
  if (!empty($variables['node'])) {
    $variables['theme_hook_suggestions'][] = 'page__node__' . $variables['node']->type;

so you can have page--node--news.tpl.php for news content type ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.