Conditional Tags

From Habari Project

Jump to: navigation, search

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'; ?>
<?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'; ?>
<?php } ?>
Personal tools
This is a cached copy of the requested page, and may not be up to date.

Sorry! This site is experiencing technical difficulties.
Try waiting a few minutes and reloading.

(Cannot contact the database server: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) (localhost))

You can try searching via Google in the meantime.
Note that their indexes of our content may be out of date.