• I’d like to have new pages show up on my as well as posts. I’d like to use pages, because I want the urls to contain subdirectories based off the parent pages for easy navigation that can go several levels deep. Obviously, I’d need to limit which pages get added to the blog so that it doesn’t like things like my privacy page and about me, etc.
    Is there a plugin or some simple code I can use that will allow me to select which specific pages can show on my blog?
    Thanks
    Dan

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Wouldn’t it make more sense to exclude certain pages? Otherwise every time a new page is created you would need to add it to the list, or is that really your intent? Code where the excluded pages are hardcoded is pretty simple. Code to select which pages to include would involve creating an admin page, so is more involved.

    Exclusion code would look like this:

    function cb3_include_pages( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'post_type', array('post', 'page') );
            $query->set( 'post__not_in', array( /*list all excluded page IDs here*/ ) );
        }
    }
    add_action('pre_get_posts', 'cb3_include_pages');

    You’ll need to determine all page IDs to exclude, but once done the code will need little attention until you create another page that must be excluded.

    Thread Starter Cerebrus3x

    (@cerebrus3x)

    Hey Thanks a lot, I’m going to try this. I was hoping there would be a plugin or something that would do this for me so that I’d not have to mess with code, but I haven’t been able to find one. So I’m going to back my stuff up and mess around with this to see if I can make it workout.
    Thanks bcworkz

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Display specific pages in blog’ is closed to new replies.