Support » Fixing WordPress » Different displays on different page types

  • Is there any easy way of having different page elements on different view types?
    e.g., different sidebar content for each view. I don’t want a sidebar linkblog to display on any page but the front/”last n” entries page; other information (like an Amazon links if I’m talking about a particular book) is only suitable for single-entry pages, etc.
    Another conceivable application would be showing full text entries only on the “last n“, day and single entry views, excerpts on monthly archive pages, and only titles on yearly archive pages.
    I’ve dodgily hacked wp-blog-header.php to get this sort of working, but the less said about that the better. (It feels dodgy, doesn’t even work with all use-cases, etc.)
    Is there some convenient way to do this? Even just a pointer to relevant documentation/code would be helpful. 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’ve found the following pretty helpful:
    <?php if ($single) { ?>
    Stuff you want only on a single post page
    <?php } ?>
    <?php if (!$single) { ?&gt
    ;Stuff you want only on a non-single pages
    <?php } ?>

    Oops. Second on should be:
    <?php if (!$single) { ?>
    Stuff you want only on a non-single pages
    <?php } ?>
    If you want to specify particular stuff for other archive pages too, you’d have to get a bit more complex but I find just the single and not-single to be fine for me.

    Thanks, I knew about $single, it’s the “bit more complex” part that’s messing with me. 🙁
    At the moment I’ve added various $pagetype = 'month';, $pagetype = 'day'; type things to wp-blog-header.php. If $year isn’t null then $pagetype is set as ‘year’; Then $month is checked, and if not null then $pagetype is set as ‘month’, then $day etc.
    In the template pages I can put <?php if ($pagetype == 'month') { blah blah; } ?> etc.
    This works, but it’s not very elegant and doesn’t cover everything (search results, category views). And, obviously, editing files every time there’s an upgrade is annoying. I’m not great with PHP, which is why I was hoping someone could point out something blindingly obvious that I’ve missed…

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Different displays on different page types’ is closed to new replies.