WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking to create a behavior as shown in the following link:


Here all posts from the same category are being displayed. Currently, it is handwritten HTML code, I want to mimic this behavior using PHP code in my single.php.


Following is the code I have written so far

$category = get_the_category();

if ( have_posts() ) : while ( have_posts() ) : the_post();
   <li><a href="get_permalink( $id );">the_title();</a></li>
endwhile; endif;


Can someone help in making it work?

share|improve this question
up vote 0 down vote accepted

try this ;

$cat = get_query_var('cat');
$PozCat = get_category ($cat);
$PozCat->id // give to us current cat id.

Than use this hook in your query ;

    $cat = get_query_var('cat');
    $PozCat = get_category ($cat);
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <li><a href="<?php the_permalik();?>"><?php the_title(); ?></a></li>

    <?php endwhile; endif; ?>
share|improve this answer

You can do this using Wp_query() by passing the category name as an argument:

<?php $my_query = new WP_Query('category_name=mycategory&showposts=-1'); ?>

<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">

<?php the_title(); ?></a>

<?php endwhile; ?>
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.