WordPress.org

Ready to get started?Download WordPress

Forums

Display posts from selected categories in a page (5 posts)

  1. apek
    Member
    Posted 5 years ago #

    Hi all,

    I have a few categories which i named Media Releases, In The News and Events. I want to display all posts (the post links) from these categories in a page.

    Currently this is what i'm doing:
    <?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("showposts=5&paged=$page&cat=14&cat=3&cat=9"); while ( have_posts() ) : the_post(); $loopcounter++; ?>

    If you notice, i use cat=14&cat=3&cat=9 to display post links from the 3 categories i mentioned earlier. The numbers are the category numbers.

    I thought i have succeed to do it because at the first place, i only post content to the category number 9 (cat=9). Just now i write a content which fall under the cat=14 and cat=3. Unfortunately, the page still showing contents from cat=9 only. I try to change the sequence to
    cat=9&cat=3&cat=14 and now the page is only showing post under cat=14. So i can say that it only show the last category.

    Can anyone help me to display the other 2 categories?

  2. cancatis
    Member
    Posted 5 years ago #

    Sending 3 requests like that isn't the best choice, I believe. You could place them together (like in cat=3,9,14) and have the code sparse that for you. Using then a while function.

  3. cancatis
    Member
    Posted 5 years ago #

    foreach function, sorry.

  4. apek
    Member
    Posted 5 years ago #

    its working when i put comma like that..but the loop still using while function.

    thannks!

  5. VengeanceFury
    Member
    Posted 5 years ago #

    I'm looking at displaying posts from a category in a page. (The rest of my pages need to remain as pages). Is what you are doing here doing just that? What other code/modifications do you have to your theme to enable it to work and where are you placing the code you have provided above?

    Thanks in advance for any help.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags