1

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

http://www.javaexperience.com/java-role-of-serialversionuid-in-serialization/

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.

posts

Following is the code I have written so far

<?php
$category = get_the_category();
   <ul>

query_posts('cat='.$category);
if ( have_posts() ) : while ( have_posts() ) : the_post();
   <li><a href="get_permalink( $id );">the_title();</a></li>
endwhile; endif;
   </ul>
<br/>

?>

Can someone help in making it work?

2 Answers 2

3

Try this:

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

Then use this hook in your query:

<ul>
   <?php
    $cat = get_query_var('cat');
    $PozCat = get_category ($cat);
    //$PozCat->id
    query_posts('posts_per_page=-1&cat='.$PozCat->id);
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

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

    <?php endwhile; endif; ?>
</ul>
1
  • 1
    works great, except for the_permalink() typo
    – Grant
    Dec 14, 2018 at 5:27
-2

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; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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