• Hey Guys,

    I have searched the internet for the last hour trying to look for a solution to my problem, but I either cannot find it, or am looking for the wrong thing.

    I am using…

    <?php $recent = new WP_Query(“showposts=3”); while($recent->have_posts()) : $recent->the_post();?>

    …to display some recent posts in my sidebar. It works really well. So I want to use it to display 3 posts from a specific category, on my blogs homepage.

    I have the working code on my home page, its displaying the correct number of posts, but I cannot work out how to make it only show posts from a specific category. In this case, I want only posts from the ‘Gallery’ category, to show up. That cat number is 10.

    What do I have to add to the code to make it only show posts from that category please?

Viewing 4 replies - 16 through 19 (of 19 total)
  • Spotted 1 error – I missed an opening <?php before if( $c == 4) :?>

    Amended code: https://wordpress.pastebin.com/PRtCYBw1

    Thread Starter andymacdonalduk

    (@andymacdonalduk)

    Hey there Esmi,

    That did the trick perfectly, thank you very much! Are you able to give me a rough Idea of what exactly was done there please?

    You mentioned Id have to re-do my CSS which isn’t a problem, but are you able to point me in the right direction on where roughly I need to be looking please?

    I guess what Im asking, is what has actually changed in the above code, which would mess up the css layout of the featured gallery, so I know where I should start looking so I can fix the changes?

    Thanks again. ??

    Thread Starter andymacdonalduk

    (@andymacdonalduk)

    Esmi, please ignore my last post.

    I have worked out the CSS layout and now have it working perfectly. Thanks again for your amazing help!! I really appreciate it.

    Thread Starter andymacdonalduk

    (@andymacdonalduk)

    Esmi, I have a question, if you don’t mind?

    You know you showed me how to have four of the latest posts from my ‘Gallery’ category show up in a four-column section of my home page?

    Is there a way to do exactly the same thing, but output categories instead? I have individual categories inside my gallery, but I want to create a gallery page which is specifically designed to be the ‘springboard’ to push people to those individual gallery categories.

    So for example. When somebody clicks on a gallery page, I want a page to be displayed which shows a list of categories inside the ‘gallery’ category. Maybe the icon for each category could be the latest picture added in the latest post inside that specific category.

    Does that make sense, and is anything like that possible?

Viewing 4 replies - 16 through 19 (of 19 total)
  • The topic ‘How Can I Use WP_Query to Display Posts from Only ONE Category?’ is closed to new replies.