• hi again to this awesome community.

    is there any smart way of displaying Posts within a category when a condition is true..

    i have made the following statement

    if is category & single

    then do the following..

    now i want to display the posts within that category.

    is there anything called wp_list_single or any smart way of doing it

    advanced thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • You want to display posts within a given category in a single post?

    Thread Starter cocacooler

    (@cocacooler)

    yes as a sidebar

    Something like:

    <?php if( is_single() ) :
    global $post;
    $categories = get_the_category($post->ID);?>
    <ul>
    <?php $args = array(
    	'cat' => $category[0]->ID,
    	'posts_per_page => -1
    );
    $the_query = new WP_Query( $args );
    while ( $the_query->have_posts() ) : $the_query->the_post();?>
    <li><a href="<?php the_permalink();?>"><?php the_title(); ?></a></li>
    <?php endwhile;?>
    </ul>
    <?php wp_reset_query();
    wp_reset_postdata();
    endif;?>

    should work.

    Thread Starter cocacooler

    (@cocacooler)

    when i use this code :

    <?php wp_list_categories('include=1,2,3&title_li=&orderby=id'); ?>

    then it populates a list with styling…
    but the above mentioned code doesnt populate url with styling
    and its also not highlighting the current open post.
    i used this code to display the posts

    global $post;
    $args = array( 'numberposts' => 4,'order'=> 'asc', 'category' => 14 );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :	setup_postdata($post); ?>
    	<li class="cat-item"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘wp list single issue’ is closed to new replies.