Support » Fixing WordPress » New posts in a specific page

  • Hi all.

    Is possible to publish posts of a certain category to a specific page and *not* in the front page?

    Is there a plugin?

    Thanks in advance.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Sure, write a template for your page that uses query_posts instead of the normal loop e.g. <?php query_posts($query_string . '&cat=-3,-8'); ?> would exclude categories 3 and 8.

    http://codex.wordpress.org/The_Loop#Exclude_Posts_From_Some_Category

    Then you could use http://codex.wordpress.org/Pages#A_Page_of_Posts or another template that uses query_posts for the page that you only want to show posts from one category on.

    Thanks but it looks too complicated for me. Is there a plugin, so I don’t have to write code?

    I am not aware of any. You are actually asking to do two things. Exclude a category from the main blog page and also have a page that only shows posts from one category.

    I used in combinations the plugins “simply exclude” and “associated posts” but after upgrading to 3.1 one of the plugins doesn’t work.

    It’s not a hard thing to code. You basically have to replace a couple of lines of code. You basically have to replace:

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    with

    <?php
    //The Query
    query_posts($query_string . '&cat=-3,-8');
    //The Loop
    if ( have_posts() ) : while ( have_posts() ) : the_post();
     ?>

    Exclude whatever categories you like, and then on the page template where you want to show post from only one category you would replace it with something like:

    <?php
    //The Query
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('posts_per_page=5&cat=3&paged=' . $paged);
    //The Loop
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    
    ?>

    Make a copy of page.php of your theme and name it page-slug.php or page-id.php (replace slug or id with the actual slug or id) and put that code in it and you’re good to go. WordPress will automatically use that template when you display that page. This code will display 5 posts per page from category 3 only.

    HTH

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘New posts in a specific page’ is closed to new replies.