Conditional Tags
From Habari Project
Revision as of 22:16, 3 November 2008 by wilcosworld (Talk | contribs)
When creating a theme, there are occasions where you wish to only show certain sections of your theme's template depending on what page your visitor is viewing. For example, you might wish to display a list of all tags used within the sidebar.
$request is a member variable of the theme class you are using, there are a number of built-in page types that can be attributes of the $request object.
- display_home
- display_entries
- display_entries_by_date
- display_entries_by_tag
- display_entry
- display_page
- display_search
- display_404
In the example below the search form will only display when not viewing the search results page(s).
<?php if( !($request->display_search ) ) { ?> <li id="search"> <?php include 'searchform.php'; ?> </li> <?php } ?>
If you wanted content to appear only on one specific page, you would use $post->slug to call the page name. In the example below the search form will only display when viewing a page with the slug 'contact'.
<?php if ($post->slug == 'contact') { ?> <li id="search"> <?php include 'searchform.php'; ?> </li> <?php } ?>