SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    wp_list_pages & horizontal menu

    I'm trying to get a horizontal menu of Pages in the header, but it won't seem to work unless wp_list_pages('title_li=') has something in it and then display it's content like "Pages:" I don't want this.

    Right now I'm modifying the post-template.php file by adding the "!" to "if ( !$r['title_li'] )". I don't want this either. There must be a better way through css.

    post-template.php
    Code PHP:
    function wp_list_pages($args = '') {
    $defaults = array(
    		'depth' => 0, 'show_date' => '',
    		'date_format' => get_option('date_format'),
    		'child_of' => 0, 'exclude' => '',
    		'title_li' => __('Pages'), 'echo' => 1,
    		'authors' => '', 'sort_column' => 'menu_order, post_title',
    		'link_before' => '', 'link_after' => ''
    	);
     
    	$r = wp_parse_args( $args, $defaults );
    	extract( $r, EXTR_SKIP );
     
    	$output = '';
    	$current_page = 0;
     
    	// sanitize, mostly to keep spaces out
    	$r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']);
     
    	// Allow plugins to filter an array of excluded pages
    	$r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude'])));
     
    	// Query pages.
    	$r['hierarchical'] = 0;
    	$pages = get_pages($r);
     
    	if ( !empty($pages) ) {
    		if ( !$r['title_li'] ) // I ADDED THE ! SIGN HERE
    			$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
     
    		global $wp_query;
    		if ( is_page() || is_attachment() || $wp_query->is_posts_page )
    			$current_page = $wp_query->get_queried_object_id();
    		$output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
     
    		if ( !$r['title_li'] ) // I ADDED THE ! SIGN HERE
    			$output .= '</ul></li>';
    	}
     
    	$output = apply_filters('wp_list_pages', $output);
     
    	if ( $r['echo'] )
    		echo $output;
    	else
    		return $output;
    }

    .css file
    Code CSS:
    .pagenav li{
    	display: inline;
    }

    header.php
    Code PHP:
    <h1 id="header"><a href="<?php bloginfo('url'); ?>/"><?php bloginfo('name'); ?></a></h1>
    <?php wp_list_pages('title_li='); ?>
    <div id="content">
    <!-- end header -->

  2. #2
    Barefoot on the Moon! silver trophy
    Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,528
    Mentioned
    52 Post(s)
    Tagged
    1 Thread(s)
    http://codex.wordpress.org/Template_Tags/wp_list_pages

    Use the "exclude" option. To get the ID of the page you want to exclude, just look at the link.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guess that wasn't clear.

    The text "Page:" is there by default and I can't get horizontal listing of pages without that text or something else in it's place.

    I want this.
    Home Services Downloads



    Not this.

    Page:
    Home Services Downloads

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    PHP Code:
    <?php echo '<li class="pagenav"><ul>' ;
    wp_list_pages('title_li='); 
    echo 
    "</li></ul>" ;
    ?>
    I manually added the tags that were getting stripped out by "title_li=" being empty. It works.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •