Quick PHP Question

by 3 replies
4
The wordpress theme I am currently using is currently set up to only display the most recent posts from one particular category on the blog's homepage. You will see below, by default it is category 1. I would like to be able to have the front page display posts from all categories, or at least be able to add additional category numbers.

Ideally I would like it to display the last 6 posts from any category instead of 5 posts from category 1 as shown in the code below.

Any ideas how I can accomplish this?


Code:
 <!--Replace cat=1 with the Category ID you want to display in this section.-->
                
<?php $recent = new WP_Query("cat=1&showposts=5"); while($recent->have_posts()) : $recent->the_post();?>

  <?php if( get_post_meta($post->ID, "thumbnail", true) ): ?>
  <a href="<?php the_permalink() ?>" rel="bookmark">
<img style="float:left;margin:0px 10px 0px 0px;" src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" alt="<?php the_title(); ?>" /></a>
#main internet marketing discussion forum #php #question #quick
  • If you just want to modify what you have above:
    <?php $recent = new WP_Query("showposts=6"); etc....

    Another option would be to use the standard Loop in your template file, although it is difficult to advise when not seeing the whole file.
    There might be another Loop in the same template file, otherwise using the "new WP-Query" wouldn't make any sense.
    (not that I didn't see templates with code that doesn't make any sense )
    • [ 1 ] Thanks
    • [1] reply
  • You could use the get_categories function and create a loop to display certain number of post from each category. Check out this page on wordpress codex

    Function Reference/get categories WordPress Codex

    That function allows you to place the formation about the category in an array. Then you can use the catergory information in the WP_Query call.

    Rodney
    • [ 1 ] Thanks

Next Topics on Trending Feed

  • 4

    The wordpress theme I am currently using is currently set up to only display the most recent posts from one particular category on the blog's homepage. You will see below, by default it is category 1. I would like to be able to have the front page display posts from all categories, or at least be able to add additional category numbers. Ideally I would like it to display the last 6 posts from any category instead of 5 posts from category 1 as shown in the code below.