Eazy help: Query Posts from category id

Discussion in 'PHP' started by batoo, May 27, 2010.

  1. #1
    Hey all.
    I need little help. I use wordpress latest version and there is functions to query posts from category. Also there is function to get category id.

    So i can make query for exact category like
     <?php query_posts('cat=30&orderby=comment_count'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <li style="list-style:none"><b><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></b></li>
    <?php endwhile;?>
    Code (markup):
    to get category id , code is
    get_query_var('cat')
    Code (markup):
    but when i try to use
    <?php query_posts('cat=get_query_var('cat')&orderby=comment_count'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <li style="list-style:none"><b><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></b></li>
    <?php endwhile;?>
    Code (markup):
    i get error.

    What is right syntax to make it works?
     
    batoo, May 27, 2010 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2
    You are trying to pass it in as a string, which is why you are having the problem. Either get the data first, and pass in the response, or concatenate the request inside the function;

    E.G

    <?php query_posts('cat='.get_query_var('cat').'&orderby=comment_count'); ?>
    PHP:
     
    lukeg32, May 28, 2010 IP