Dev:Listing Published Pages

From Habari Project

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.

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

See Retrieving Posts for more ways to access specific posts.

Personal tools