WordPress.org

Ready to get started?Download WordPress

Forums

Easiest way to separate two different categories over two different pages? (19 posts)

  1. betwixt
    Member
    Posted 6 years ago #

    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.

    Regards,
    DM

  2. betwixt
    Member
    Posted 6 years ago #

    Anyone? :)

  3. Chris_K
    Member
    Posted 6 years ago #

    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?

  4. betwixt
    Member
    Posted 6 years ago #

    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"> 
    
    <?php
        $events_cat = '7'; 
    
        if (!is_paged()) {
            query_posts('cat=' . $events_cat);
        } else {
            query_posts('cat=' . $events_cat . '&paged=' . $paged);
        }
    ?>
            <?php include (TEMPLATEPATH . '/theloop.php'); ?> 
    
        </div> 
    
        <?php get_sidebar(); ?> 
    
    </div> 
    
    <?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:)

    Regards,
    Dennis

  5. Chris_K
    Member
    Posted 6 years ago #

    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:
    http://wordpress.org/extend/plugins/advanced-category-excluder/

  6. betwixt
    Member
    Posted 6 years ago #

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

    Regards,
    DM

  7. betwixt
    Member
    Posted 6 years ago #

    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" ?

    Regards,
    DM

  8. Chris_K
    Member
    Posted 6 years ago #

    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

  9. betwixt
    Member
    Posted 6 years ago #

    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?

  10. asony999
    Member
    Posted 6 years ago #

    Hi,

    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.

  11. betwixt
    Member
    Posted 6 years ago #

    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.

    Regards,
    DM

  12. dkaye315
    Member
    Posted 6 years ago #

    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.

  13. betwixt
    Member
    Posted 6 years ago #

    @ 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 :(

  14. asony999
    Member
    Posted 6 years ago #

    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.

    Thnaks.

  15. dkaye315
    Member
    Posted 6 years ago #

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

  16. asony999
    Member
    Posted 6 years ago #

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

    ..
    ()
    --

  17. dkaye315
    Member
    Posted 6 years ago #

    whoops, sorry - i failed to catch the part about 3 different categories on one page. i'll pay better attention next time. ;)

  18. asony999
    Member
    Posted 6 years ago #

  19. aliyazia
    Member
    Posted 6 years ago #

    Hi all,

    I have a problem which u ppl might help. im developing english and arabic website using wordpress. i have created to home page one with arbic layput and one with english layout. The pages part are working fine. but when it comes to category...i have one arhive.php to display categories in english. but how should i display arabic categories??? if a create another archive_ar.php ..which i have done for pages... i cant select the archive_ar.php from admin of post write.

    I hope im clear.....

    Can any body help...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.