Forums

[resolved] Ordering by Specific Category PHP (4 posts)

  1. artslob
    Member
    Posted 1 year ago #

    Hello. I'm trying to make a category display instead of random posts in slide.php of Zinmag Tribune theme.

    I'm editing slide.php which rotates thumbnails and descriptions of certain posts. originally the code looked like this

    $my_query = new WP_Query('orderby=rand &showpost=2');
    while ($my_query->have_posts()) : $my_query->the_post();$do_not_duplicate = $post->ID;

    I would just like to switch the 'orderby=rand to display posts from a specific category instead of random posts.

    I did change it to 'orderby=category and it is now only displaying posts from the front page for some reason. Any help greatly appreciated.

    cheers

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    try:

    my_query = new WP_Query('posts_per_page=2&cat=8');

    Change 8 to the category ID you want

    http://codex.wordpress.org/Function_Reference/query_posts

  3. artslob
    Member
    Posted 1 year ago #

    works like a charm! Thank you so much!

    It should be noted that you also need a $ at the beginning for the call to function
    $my_query = new WP_Query('posts_per_page=2&cat=8');

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    Oops, didn't copy paste the whole thing. Glad you got it working.

Topic Closed

This topic has been closed to new replies.

About this Topic