WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Need Help with showing pages; code fix (4 posts)

  1. ffgdirector
    Member
    Posted 5 years ago #

    I am having trouble correcting a bit of modification to a templates code. MichaelH, one of the moderators was very helpful and was able to show me how to not display certain posts by replacing this:

    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;
     }

    with this:

    if ( $the_page_id != '2' && $the_page_id != '3' && $the_page_id != '4' ) {
    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;
     }
    }

    However, now I'm having trouble getting any new pages to display. That code seems to make any pages that were added after I put it in invisible. I tried changing the pageid numbers in the code but it had no effect. Does anyone know how to correct this? I couldn't send it in a pm to MichaelH because pm's don't seem to exist. So any help I can get would be appreciated.

  2. ffgdirector
    Member
    Posted 5 years ago #

    Could someone please help?

  3. MichaelH
    Member
    Posted 5 years ago #

    Okay, I've deleted your duplicate thead...thanks for chasing me down.

    Since the goal is to have only certain pages displayed in your header, then delete the previous modifications and if necessary get the theme's orginal header.php.

    Then change this line:

    $these_pages = $wpdb->get_results('select ID, post_title from '. $wpdb->posts .' where post_status = "publish" and post_type = "page" order by ID');

    to:

    $these_pages = $wpdb->get_results('select ID, post_title from '. $wpdb->posts .' where ID IN (2,218) AND post_status = "publish" and post_type = "page" order by ID');

    Note: the (2,218) is retrieving page IDs 2 and 218. You will just want to add or change that list to reflect your own Page IDs.

  4. ffgdirector
    Member
    Posted 5 years ago #

    Thanks! That works perfectly, and I don't even have to go in and edit it when I edit new pages. I only have to edit it when I want them to appear. Thanks again for all the help.

Topic Closed

This topic has been closed to new replies.

About this Topic