0
votes

I did find one topic that sort of touched base on this but if there is a better link please advise.

I have a self hosted Wordpress website set up typically for a static home page and a separate page that shows recent posts called "Reviews". I need to write posts under a category "Recent News" that would be excluded from the recent post and shown on their own page, a second blog page.

The Codex tells me to add this to the index.php to exclude the category "recent-news":

<?php
if (is_home()) {
query_posts("cat=-3");
}
?>

with 3 being "recent-news". This does nothing no matter where I place it on the page. It still shows up with the recent posts. I'm guessing I'm in the wrong section for excluding categories in the Codex.

How do I exclude a category from recent posts, add a new page called "Recent News" and have it only show posts from the 'recent-news" category.

or have I climbed down a rabbit hole...

2
cat=-3 is a parameter to your Wordpress query, you need to add it as a parameter to your loop / wp_query call. Just pasting it to page will not work. As always, start with reading the documentation: codex.wordpress.org/The_Loop#Exclude_Posts_From_Some_Category - Petr Cibulka
That is very helpful, and I ended up with that snippet via a wordpress.org forum topic. That is where they said to just place it in the index.php. Thank you for the link @PetrCibulka, is what I'm trying to achieve though, possible? Two seperate post pages? - Deyo
Of course. Follow the advice of Talsibony below. However it seems that your knowledge of Wordpress is somehow limited, so I would recommend for you to read some beginner articles/tutorials first ... - Petr Cibulka
@PetrCibulka you are correct, and that is why I am here to learn, but will also take your advice on reading many resources, Thank you. - Deyo
There are many resources online. Official WP beginner roundup is here (pointed to the chapter which applies to your current situation): codex.wordpress.org/… Read more about Wordpress loop and template files / template hierarchy. - Petr Cibulka

2 Answers

0
votes

you can do it like this: edit your index.php page or create a custom template and then create a page (say "Front Page" ) and assign this template to it. In this template, copy your index.php code or if you feel confident simply create your template and include this code:

<?php if (have_posts()) : ?>
    <?php $my_query=new WP_Query( 'cat=-3'); while 
   ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID;  ?>
    <div class="post">
        <h3><?php the_title(); ?></h3>
    <?php the_content(); ?>
    </div>
    <?php endwhile;?>
    <?php endif;?>

About your second question, simply go to Appearance --> Menu and there you'll see you can add pages but also categories. Simply select the category "Recent News" as a menu element and voilá, now you'll have a page displaying only posts from that category

0
votes

I do not recommand messing with index.php I think you should create a page template that will query posts from "Recent News" category. Then in wordpress create a page and choose the page template you created. In order to set it as the home page you will have to set it via wordpress configurations. Wordpress page template

query posts by category

Set static homepage