• wp community,

    I have tried super hard to resolve this question by reading up on pages; the loop; templates; themes; conditional tags, and template hierarchy.

    i’ve seen variations of this question a few times in these forums. the answer is usually “read this page (such as templates page or theme page)”. that’s often the last comment in the thread. my gut tells me it’s because they were intimidated; not that they figured it out by reading the suggested page.

    here is what i’m trying to accomplish: i have a series of posts that are category-3, or “news”. i don’t want them to appear on the blog page; only on the news page. i used the following code to omit them from the blog page:

    function exclude_category($query) {
    if ( $query->is_home ) {
    $query->set('cat', '-3');
    }
    return $query;
    }

    what i can’t accomplish: how do i get the posts w/ category-3 to appear on a page titled “news”?

    i’m using the Kubrick theme.

    thank you!!!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • read this first or later:
    pages:
    http://codex.wordpress.org/Pages
    http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates

    make a copy of index.php and call it ‘news-template.php’ for instance.
    edit it and put this code into the top:

    <?php
    /*
    Template Name: News Template
    */
    ?>

    query_posts:
    http://codex.wordpress.org/Template_Tags/query_posts
    http://codex.wordpress.org/Template_Tags/query_posts#Category_Parameters

    go down to after:

    <div id="content" class="narrowcolumn" role="main">

    add the line to news-template.php:

    <?php query_posts('&cat=3'); ?>

    in ‘admin’ – ‘pages’ – ‘add new’: make a new page with the title ‘news’

    on the right under ‘attributes’ ‘template’ click the drop down menu and select ‘news template’.

    save and publish the page.

    back into view site: if you have the ‘pages’ widget in the sidebar, you should see the page ‘news’.
    click it, and you should see the posts with category-3.

    you will see that after a while even the codex begins to make sanse to you 😉

    Thread Starter sergibosch

    (@sergibosch)

    alchymyth

    thanks much! have experience with all the above except for the “magical snippet”: <?php query_posts('&cat=3'); ?>

    i really appreciate your time to post this response. gonna tackle your suggestion.

    Thread Starter sergibosch

    (@sergibosch)

    hi, alchymth,

    i wanted to follow up. maybe this post will be helpful to others.

    once i implemented the solution you suggested for targeting posts of category 3, the function i had been using stopped working.

    final solution:
    use <?php query_posts('&cat=3'); ?> to have only category-3 post appear.

    and use `<?php
    if (is_home()) {
    query_posts(“cat=-3”);
    }
    ?> ` to omit category-3 posts from the blog page.

    helpful link: http://codex.wordpress.org/Template_Tags/query_posts#Post_.26_Page_Parameters

    thanks again for your help!

    Thread Starter sergibosch

    (@sergibosch)

    another follow up:

    you have to be careful with putting running query_posts as i did, in that it will ruin your pagination, such as links to “older entries” and “newer entries”. you can read about such dangers here: http://codex.wordpress.org/Template_Tags/query_posts

    here is the final snippet i used to prevent posts of a certain category from appearing on the blog page:

    global $wp_query;
    query_posts(
    	array_merge(
    		array('cat' => -3),
    		$wp_query->query
    	)
    );
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘controlling posts without a plugin, using Kubrick’ is closed to new replies.