Forums

How to display different categories on different pages (4 posts)

  1. polygonjedi
    Member
    Posted 7 months ago #

    Hello guys

    Just a beginner seeking some help. I am writing a if clause to display different categories on different pages.

    LOGIC :
    If the PAGE with the ID - 128 is displayed, I need to display all the posts under the category -tamtam or else for any other pages, I need to display all the post under the category - main.

    This is my code and its not working :(

    <?php if ( the_ID('128') ) { ?>
    <?php query_posts('category_name=tamtam&posts_per_page=1'); ?>
     <?php } else { ?>
    <?php query_posts('category_name=main&posts_per_page=4'); ?>
     <?php } ?>

    It would be really great if anyone can help.
    Thankyou

  2. alchymyth
    The Sweeper
    Posted 7 months ago #

    is there a reason why you don't use the category archive pages and create the category links in your menu?

    what you are asking can be possibly be done in two ways:

    - either create a page template for each category http://codex.wordpress.org/Pages#Page_Templates

    - or use the 'page-links-to' plugin http://wordpress.org/extend/plugins/page-links-to/ to link the pages to the category archives

  3. polygonjedi
    Member
    Posted 7 months ago #

    The Page template worked. That was awesome and Thanks

    However there is another problem.

    Page-main has 4 posts from category-two as its sidebar. Now when I click on any of the post under category-two , its takes to me that post but the sidebar shows posts from other categories.
    Is it possible to display category-two's posts only while I click on any of the postin category-two.

    Like how the page template, is there a way for posts too ?

    How about this logic on the side : If clause saying that if the post ID's are 1,2,3.. etc then display category-two or else display none

    I'm not good at coding php. But I can derive a logic as above. So guys, any help ?

  4. polygonjedi
    Member
    Posted 7 months ago #

Reply

You must log in to post.

About this Topic