0

I have the following function in functions.php page

function viewpost($num)
{
   echo $num;
   query_posts('order=dsc&cat=$num & showposts=2');
   while (have_posts()) : the_post(); 
   ?> <span> <?php  the_title(); ?> 
   <?Php 
   echo get_the_post_thumbnail();
   the_excerpt();
   ?> 
  <?Php 
  endwhile;
  wp_reset_query();  
}

When I call viewpost function for values of viewpost(1)(to view post from category one ) it shows correct values, but when I put the same function again viewpost(2) (to view post from category 2) it shows the previous function values i.e. from category. What can I do to get the post from different categories by changing the passing value

Tim Seguine
  • 2,887
  • 25
  • 38

1 Answers1

0

Without trying your code, I think the most likely problem is you're using single quotes. Variable names won't get expanded to their values. See this answer.

Try

query_posts("order=dsc&cat=$num&showposts=2");

instead of

query_posts('order=dsc&cat=$num & showposts=2');

This might be worth a read too. Using query_posts is normally not recommended.

Community
  • 1
  • 1
Hobo
  • 7,536
  • 5
  • 40
  • 50