On my single.php i want to show the current post and underneath it i want to list all the posts in cat-2. In my loop i tried to query post with cat-2 but it still shows the current post.

<?php global $query_string;
$posts = query_posts($query_string.''); ?>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
                <h4><?php the_title(); ?></h4>

            <?php endif; ?>

            <?php the_content(); // Dynamic Content ?>
            <?php edit_post_link(); ?>    
    <?php endwhile; ?>
    <?php else: ?>
            <h1><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h1>

    <?php endif; ?>
<?php rewind_posts(); ?>

<hr>
<?php global $query_string; // required
$posts = query_posts($query_string.'&cat=2,&order=ASC'); ?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <a href="<?php the_permalink(); ?>"><img title="<?php the_title(); ?>" alt="<?php the_title(); ?>" class="wp-post-image" src="<?php the_post_thumbnail_url(); ?> " style="width:100%; height:auto;"></a>
        <h4><?php the_title(); ?></h4>
    </div>
</div>

<?php endwhile; ?>

<?php else : ?>

<?php endif; ?>

<?php wp_reset_query(); // reset the query ?>

Read more here: Show other category posts in single.php


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: