Dev:Listing Published Pages

From Habari Project

Revision as of 02:35, 29 September 2010 by michaeltwofish (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

If you want to list all your published pages you could use a plugin like pagemenu which allows you to move, edit and control menu items or, alternatively, you can simply list them with a few lines of code.

We're going to describe this second method. First you need to put this inside theme.php

public function add_template_vars()
{
  if ( !$this->template_engine->assigned('pages') ) {
    $this->pages = Posts::get(array(
      'content_type' => 'page', 
      'status' => Post::status('published'), 
      'nolimit' => 1))
    );
  }
}

Now the $pages variable should become available to your theme and you can use a code similar to this one to create a very simple navigation that lists all your published pages.

<ul>
<?php foreach ( $pages as $page ): ?>
  <li>
    <a href="<?php echo $page->slug; ?>"><?php echo $page->title; ?></a>
  </li>
<?php endforeach; ?>
</ul>

See Retrieving Posts for more ways to access specific posts.

Personal tools