views:

68

answers:

1

I'm trying to create a teaser node template to display all Blog teasers. For the page tpl I have page-blogs.tpl.php For the Blog node tpl I have node-blog.tpl.php (This one is looping to display all the blog teasers) Now how do I create a node template to surround the node teasers? My URL for the page with all the blog teasers is: /blogs/eric My URL for the page with an example blog entry is: /blogs/eric/test-blog-1 I need a node template that I can use for all the Blog pages. I tried using node-blogs-teaser.tpl.php for the individual teaser nodes and node-blog.tpl.php for the outer blog node template, but that didn't work.

Here is what I have in my node-blog.tpl.php file:

<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">
<div class="item">
<ul>
<?php print $picture ?>

<?php if ($page == 0): ?>
<?php endif; ?>

  <div class="content clear-block">

    <li class="title"><h4><?php print $title ?></h4></li>
    <li class="photo"><a href="#"><img src="/<?php print $node->field_blog_image[0]['filepath']; ?>" /></a></li>
    <li class="desc"><?php print $node->content['body']['#value']; ?></li>
    <li class="link">
    <?php if ($teaser): ?>
    <a href="<?php print $node_url ?>" class="block-link">Read more</a> | <a href="<?php print $node_url ?>" class="block-link">Audio/Video</a> | 
    <?php endif; ?>
    <?php print $submitted; ?>
    </li>
    <div class="clear"></div>     

  </div>

  <div class="clear-block">
    <div class="meta">
    <?php if ($taxonomy): ?>
      <div class="terms"><?php print $terms ?></div>
    <?php endif;?>
    </div>

  </div>
</ul>
</div>
</div>

thanks

UPDATE: I added a page preprocessor function in template.php :

/**
 * Override or insert PHPTemplate variables into the templates.
 * These are the main outer templates such as page.tpl.php 
 */
function phptemplate_preprocess_page(&$vars) {

    // add template hints using path alias
    $alias = drupal_get_path_alias($_GET['q']);
    if ($alias != $_GET['q']) {
        $template_filename = 'page';
        foreach (explode('/', $alias) as $path_part) {
            $template_filename = $template_filename . '-' . $path_part;
            $vars['template_files'][] = $template_filename;
        }
    }
    //---- 
}
A: 

Assuming your content type is called "blog", then node-blog.tpl.php will be used whenever a blog post needs to be displayed. The $teaser variable will be set to TRUE in node-blog.tpl.php if Drupal is wanting the teaser display, and the $page variable will be set to TRUE if the node is being shown in full page view (they will both be FALSE if the full node is being shown in a list of nodes). So you need to set up your node-blog.tpl.php to check for what type of display is being requested and return the HTML appropriate to the given type. The general setup of your node-blog.tpl.php should be along these lines:

if($teaser){
  //return teaser html
}
else{
  //return full node HTML
}

It's a little unclear to me from your question, but it sounds like you might have some sort of looping code in node-blog.tpl.php to iterate over the nodes on your site. You do NOT want to do this. Drupal does not work like Wordpress.

You don't mention how your list of teasers is being generated at /blogs/eric but I'd recommend using the Views module. If you use Views to generate the list of teasers then you'll be able to easily theme the list using Views' theming.

Edited since you added your example code To stick arbitrary HTML at the top of ONLY the full node display of a blog page you could edit your node-blog.tpl.php to look something like this:

<?php if ($page): ?>
My arbitrary HTML here which will not show up in teasers and only at the top of full blog pages
<?php endif; ?>

<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">
<div class="item">
<ul>
<?php print $picture ?>

<?php if ($page == 0): ?>
<?php endif; ?>

  <div class="content clear-block">

    <li class="title"><h4><?php print $title ?></h4></li>
    <li class="photo"><a href="#"><img src="/<?php print $node->field_blog_image[0]['filepath']; ?>" /></a></li>
    <li class="desc"><?php print $node->content['body']['#value']; ?></li>
    <li class="link">
    <?php if ($teaser): ?>
    <a href="<?php print $node_url ?>" class="block-link">Read more</a> | <a href="<?php print $node_url ?>" class="block-link">Audio/Video</a> | 
    <?php endif; ?>
    <?php print $submitted; ?>
    </li>
    <div class="clear"></div>     

  </div>

  <div class="clear-block">
    <div class="meta">
    <?php if ($taxonomy): ?>
      <div class="terms"><?php print $terms ?></div>
    <?php endif;?>
    </div>

  </div>
</ul>
</div>
</div>

Edited since finding out you're using the Blog module To display arbitrary HTML at the top of the listing of blog teasers just stick it at the top of page-blog.tpl.php

Aaron
Thanks Aaron.I'm not looping anything, I was trying to say that I noticed that node-blog.tpl.php is being used for each node teaser. So on the page /blogs/eric, it seems to be calling that tpl file for each teaser. What I want is a standard header above each blog page that does not repeat. I want this for the blog teaser page and for the blog full page.thanks for the help
EricP
What is at /blogs/eric that's displaying the list of blog entries? Is it a View or another module serving up that page?
Aaron
For /blogs/eric I have page-blogs.tpl.php as my main template and it's printing <?php print $content ?>.I pasted what I have in my node-blog.tpl.php file in my original post.I'm not using any views for this.
EricP
Ah, are you using the Blog module?
Aaron
Yes I am. I did modify the url's using Pathauto settings for Blogs. But nothing else.
EricP
See my edits and let me know if you have any more questions.
Aaron
Thanks Aaron, that what I'm doing already actually because I couldn't figure out any other way. In page-blog.tpl.php I'm I have a Facebook Comment App that lets people make comments on Blog posts. I only want to show this app when they are on a full blog post page like "/blogs/eric/test-blog-1" and not on the blog posts list(teaser) page. So now that I see this is my only choice, how can I tell if the blog is displaying teasers or a full blog node in page-blogs.tpl.php? Then I'll do an IF statement to show or hide the App.thanks
EricP
I see your edit's . I'll try it out. thanks
EricP
I got it working. Thank you very much for your help Aaron.With the help of my page preprocessor, I'm able to have the same page tpl file "page-blogs.tpl.php" for both of the pages(blog teaser and blog full node) like this:"Please see my edit of my first post for the function. It won't fir in this small comment box."
EricP