WordPress.org

Ready to get started?Download WordPress

Forums

Removing pages header... Proper tags not used in template (5 posts)

  1. blacloch
    Member
    Posted 6 years ago #

    Hey guys,

    This question has been asked a few times but always with a theme that has the correct WordPress conventions. Mine does not. I would like to remove certain pages from my header (actually only keep certain ones and omit all others) but the code is weird. Can you guys have a look because I know how smart you are :-)

    The code is:

    <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 . '>ID).'" title="'.$thats_all->post_title.'"><span>'.$thats_all->post_title.'</span>';
    }

    return $output;
    }
    ?>

      <?php

      if (is_home()) {
      $addclass = ' class="current_page"';
      } else {
      $addclass = '';
      }
      echo "<li" . $addclass . "><span>Home</span>";
      echo list_all_pages();?>

    Does this make sense to anyone? It is from the StudioPress theme from daily blog tips.

    Any help would be great.
    Thanks

    The theme is at
    http://www.dailyblogtips.com/studiopress-wordpress-theme-released/
    if this helps

  2. blacloch
    Member
    Posted 6 years ago #

    If anyone could help it would be much appreciated. It is pretty urgent and I have searched everywhere for an answer. Maybe Otto42?

  3. iridiax
    Member
    Posted 6 years ago #

    First, make a backup of your theme just in case things go wrong. Then, you can replace the list pages code above (be sure to keep <div id="nav">) with:

    <?php wp_list_pages(); ?>

    Learn about customizing wp_list_pages to include/exclude certain pages here (you will have to customize it and maybe add ul tags around it and span tags around the listed pages as well since the code above has them):

    I personally wouldn't want to try customizing a theme with loads of custom code like this.

  4. tommygun999
    Member
    Posted 5 years ago #

    Hi, everyone. Well, 3 months have passed since the last message on this one, but i thought that somebody might find my response useful.

    Just like blacloch, i used a studiopress template, where i wanted to exclude some certain pages. I've spent several hours on different websites, and finally, i got a clue, how to make this template work the way we want it to work. Here's the code (it goes into nav section of "header.php"):

    <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');
    wp_cache_add('these_pages', $these_pages, 'pages');
    }
    return $these_pages;
    }

    function list_certain_pages($page_ids=''){
    $page_ids = explode(',',$page_ids);
    $output = '';
    $these_pages = get_the_pa_ges ();
    foreach ($these_pages as $thats_them){
    $the_page_id = $thats_them->ID;
    if (is_page($the_page_id)) {
    $addclass = ' class="current_page"';
    } else {
    $addclass = '';
    }
    if (isset($page_ids) && in_array($the_page_id,$page_ids)){
    $output .= '<li' . $addclass . '>ID).'" title="'.$thats_them->post_title.'"><span>'.$thats_them->post_title.'</span>';}
    }
    return $output;
    }
    ?>

      <?php

      if (is_home()) {
      $addclass = ' class="current_page"';
      } else {
      $addclass = '';
      }
      echo "<li" . $addclass . "><span>Home</span>";
      echo list_certain_pages('5,9');?>

    <div class="cleared"></div>
    </div> <!-- Closes Nav -->

    _____

    In the code you can see above you simply need to change numbers in string "echo list_certain_pages('5,9');?>" with id numbers of your own static pages.

    Good luck with your blog :-)

  5. mores
    Member
    Posted 5 years ago #

    I usually install a plugin called Exclude Pages that'll let me select the pages that will be shown in the navi.

Topic Closed

This topic has been closed to new replies.

About this Topic