1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help ordering pages and removing subpages from nav

Discussion in 'WordPress' started by Artifexus, Aug 26, 2010.

  1. #1
    I need a little help editing a WP Theme. I'm using studiopress from dailyblogtips (not studiopress.com).

    My main issue is that I would like to remove my child/subpages from the top navigation. Here is the current header code:

    <div id="nav">
    <?php function get_the_pa_ges() {
      global $wpdb;
      if ( ! $these_pages = wp_cache_get('these_pages', 'pages') ) {
         $these_pages = $wpdb->get_results('select ID, post_title from '. $wpdb->posts .' where post_status = "publish" and post_type = "page" order by ID');
    
       }
      return $these_pages;
     }
    
     function list_all_pages(){
    
    $all_pages = get_the_pa_ges ();
    foreach ($all_pages as $thats_all){
    $the_page_id = $thats_all->ID;
    
    if (is_page($the_page_id)) {
      $addclass = ' class="current_page"';
      } else {
      $addclass = '';
      }
    $output .= '<li' . $addclass . '><a href="'.get_permalink($thats_all->ID).'" title="'.$thats_all->post_title.'"><span>'.$thats_all->post_title.'</span></a></li>';
    }
    
    return $output;
     }
    ?>
    <ul>
    <?php
    
    if (is_home()) {
      $addclass = ' class="current_page"';
      } else {
      $addclass = '';
      }
    
    echo list_all_pages();?>
    
    </ul>
    
    <div class="cleared"></div>
    PHP:
    What do I need to add/remove/replace to remove child pages from the top navigation? Just FYI, I altered the original code to remove the 'home' link (just 1 line I think). I'm not a php coder, so specific code and instructions would be greatly appreciated! :)

    Also, the page ordering doesn't seem to work. If I add a page, it goes to the end (right side) even using the page IDs. If I delete the preceding page and recreate it, it will go to the end. Any advice?

    Thanks in advance.
     
    Artifexus, Aug 26, 2010 IP
  2. zhoom

    zhoom Peon

    Messages:
    388
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could try a wp plugin called page lists plus. It offers a check box on each page to list in nav or not. It also lets you change the menu name of the page/post.
     
    zhoom, Aug 26, 2010 IP
    Artifexus likes this.
  3. Artifexus

    Artifexus Active Member

    Messages:
    257
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Thanks, will check it out.
     
    Artifexus, Aug 26, 2010 IP
  4. zhoom

    zhoom Peon

    Messages:
    388
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    No problem...

    As for your ordering issue, you say you are using page ids? How so? The best way to order pages is to use the page order field under the page attributes heading. Use 100 for the page you want on the right, and 1 for the page you want on the left...then use other numbers in between to order your other pages...
     
    zhoom, Aug 26, 2010 IP
  5. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #5
     $these_pages = $wpdb->get_results('select ID, post_title from '. $wpdb->posts .' where post_status = "publish" and post_type = "page" and post_parent = 0 order by ID');
    Code (markup):
    I added a requirement that the pages have no parent so it should exclude all child pages. I have not tried it yet but it should work.
     
    Last edited: Aug 27, 2010
    Cash Nebula, Aug 27, 2010 IP
    Artifexus likes this.
  6. Artifexus

    Artifexus Active Member

    Messages:
    257
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #6
    This code seems to work. I added it and child pages are not showing. Thanks!

    I'm still having problems with the page ordering...I can change a page id and it simply won't move. Any ideas?

    Rep added for both of you that offered up suggestins. Thanks again.
     
    Artifexus, Aug 29, 2010 IP
  7. Artifexus

    Artifexus Active Member

    Messages:
    257
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #7
    I've got 4 pages right now - 3 parent and one child. I've got the code replaced as suggested by Cash Nebula. The parent page id's are 1, 2, and 50. #50 shows up before #2. Child page was 2, but now it's 75 and still no change (but my child pages are not showing due to code change - the way I wanted it). Dunno what's going on with the page ordering.
     
    Artifexus, Aug 29, 2010 IP
  8. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Where it says "order by ID", try changing that to one of these:
    order by menu_order
    order by post_title
    order by post_name
    order by post_date


    I think you need to set order numbers for the pages before menu_order will work, like is says on the Codex:
     
    Last edited: Aug 29, 2010
    Cash Nebula, Aug 29, 2010 IP
  9. Artifexus

    Artifexus Active Member

    Messages:
    257
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #9
    Hot damn! That works!

    I used order by menu order and it worked.

    Thanks again, really appreciate the help!
     
    Artifexus, Aug 29, 2010 IP