Support » Themes and Templates » Easiest way to separate two different categories over two different pages?

  • Hi there!

    I’ve read here and there through some code, but I’m a real noob when it comes to code and actually don’t have the time to dive deep into it. I was hoping to find out if there’s an easy way to accomplish what I want, without changing too much code (so when I update to a newer version of my K2 theme, every stays in tact). Perhaps I will need to work with templates, I don’t know.

    So to the point, what I’m trying to accomplish is, as the title says, having two pages with each showing posts of only one of the in total two categories with ID 4 and 7.

    I now have 5 pages of which I have created 4 myself: Blog, Portfolio, Contact, Links, Archives.

    The first page, Blog, is probably created by WordPress and shows posts of both categories. I would like to change this, so it only shows posts of the category with ID 4 (And if possible without changing much code, at a later stage other categories as well, except for category 7).

    The second page, Portfolio, is a page I created in the dashboard to display some pictures on it. So it’s not a posts page. I like to change it’s name to Photoblog, and have it only display posts with category ID 7.

    This way I want to be able to have a photoblog on the second page on which people can comment.

    What I have accomplished myself so far: I made a template which displays posts from only one category, except it shows “archive for the xx category” at the top.

    I hope you guys can help me! Thanks in advance.


Viewing 15 replies - 1 through 15 (of 18 total)
  • Anyone? 🙂

    Not sure I completely follow, but did you know that category pages are built in? No code necessary. FOr instance, if you run the default theme, check the sidebar. See the category list? Click a category and you get a page listing posts just in that particular category.

    Category_Templates might be good to look over.

    So, knowing that there’s no code necessary to display a page full of posts from a given category, what do you need help with from that point?

    HandySolo, Thanks for your help. I’m aware of the fact that there are categories in my sidebar. Though I would like to have these two categories as a page, in my top header navigation as well (and perhaps remove the category widget form the sidebar).

    So far I have been able to create a page template with the code to only display category 7, see:

    Template Name: photoblog
    */ ?>
    <?php get_header(); ?> 
    <div class="content"> 
        <div id="primary"> 
        $events_cat = '7'; 
        if (!is_paged()) {
            query_posts('cat=' . $events_cat);
        } else {
            query_posts('cat=' . $events_cat . '&paged=' . $paged);
            <?php include (TEMPLATEPATH . '/theloop.php'); ?> 
        <?php get_sidebar(); ?> 
    <?php get_footer(); ?>

    And I took a quick look in google on the search terms: “exclude category”, so I think I will be able to exclude a category from the main blog. The only thing that’s left for me to do is getting rid of the top message saying I’m browsing an archive for category “photoblog”, when I click the category or the page that displays this category. Know what I mean? Thanks:)


    and I still think that trying to force Pages to display posts is the hard way.

    Why go through all that coding? Why not just add links to those category listings in your theme’s navigation? Let WP do what it does naturally.

    And yeah, there are several plugins that you can use to exclude categories. Here’s one:

    “Why not just add links to those category listings in your theme’s navigation?”

    Several reasons.

    First off it’s my personal preference to have people arrive at my main blog and show them instantly all the posts of one category. This is because I would like to keep two categories (subjects) separated without people having to click first on either one of the two categories in the sidebar. It’s just my personal preference to not have my photoblog posts get mixed up with my default category content.

    I already managed to accomplish your suggestion by using a template for the photoblog page which displays only posts from the photoblog category. To me, this seems more or less a link without too much coding.
    The only thing I seem not be able to accomplish without coding or using a plugin, is excluding a certain category from the main out-of-the-box loop/posts page, AND getting rid of the text “You’re browsing the archive for category xx” when I click either one of the two categories. This text also appears when I use the photoblog template I created, so I guess I would need to remove some code in theloop.php. Only I think that would also get rid of the message “You’re browsing the archive for category xx” on my archive page which is what I don’t want.

    Anyway, I’ll try the plugin later tonight. Thanks for your help so far.


    The category excluder plugin works great!
    I have only two problems left, maybe you can give me a final little help? The template above doesn’t display the rollingarchive like the main page does. I tried inserting this code from the index.php, in the above template:

    <div id="primary">
    		<div id="notices"></div>
    		<?php if (get_option('k2rollingarchives') == 1) { ?>
    		<div id="dynamic-content">
    			<?php include (TEMPLATEPATH . '/rollingarchive.php'); ?>
    		</div> <!-- #dynamic-content -->

    But it seems to completely break my template….
    Also, what’s the easiest way to remove the message: “You’re browsing the archive for category xx” ?


    Afraid I’m not familiar with rollingarchives, so can’t offer much for help there.

    As for the “You’re browsing” message: You’ll find it in whatever theme file is being used to display your category listings. Check the Template_Hierarchy page, compare the files in your theme to their uses there and you should be able to determine which file you need to operate on.

    Hope that helps

    Thanks. I read alot, but still can’t figure things out.

    Also, at the K2 forum they are not replying to my questions.

    Is there no one able to point me in the right direction?


    I have also a question like this.I want to display post by categories at my site. The advanced-category-excluder works well for excluding the posts from the specific categories. But, when if you want to display posts by categories on one page, it will not work.

    So any one have any idea ?

    My question is :

    If I want to display the posts by categories on a single page, how can it is possible ?

    Thanks in Advance.

    As you can see in my third post, you find a template for a subpage to display only a certain category. In my case category with ID 7.

    You can copy my template, and change the number 7 in this code: “$events_cat = ‘7’;” to match your category ID.


    asony999 – you may want try the different posts per page plugin. it may fit the bill.

    betwixt – i encountered the same problems when i briefly used the K2 theme (edit: a while back) – that’s why i switched back from it. don’t know what the code is behind the built in plugins; however, those you’ve installed may be overriding the rollingarchives.

    @ dkaye315, the missing rollingarchive was because I had not enough posts in the category in question 🙂 My own stupid mistake. It works fine now…

    Now I have another problem with the slickr gallery showing a blank options page.. haha. Will take another few weeks to figure out that problem I expect 🙁

    dkaye315 – Thanks for suggestion. I have tried “different posts per page” plugin. But it can display post only from category.

    I want to display posts from 3 category on my home page.

    I have tried you template but I am not well in php.


    asony999 – i would check with the plugin author – when i just looked at the options, you can add as many catetgories as you want and the respective number and ordering of the posts. 🙂

    Thanks dkaye315 for your help. I have checked again the plugin, but it can display post only from 1 category per page.


Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Easiest way to separate two different categories over two different pages?’ is closed to new replies.