Search code examples
phpwordpressconditional-statementsposts

two separate blogs on one wordpress site


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...


Solution

  • 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