• How do I display the category title at the top of the list of posts retrieved from the category? I’m not having any luck finding a solution.

    My code:

    <?php $args = array( 'posts_per_page' => 3, 'category' => 1 );
    $myposts = get_posts( $args );
    foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
    
    <!--WANT CATEGORY TITLE DISPLAYED HERE-->
    
    <li>
    	<?php if ( has_post_thumbnail() ) : ?>
    	<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    	<?php the_post_thumbnail(); ?>
    	</a><?php endif; ?></div>
    
    <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
    <?php the_excerpt('Read More &raquo;'); ?>
    </li>
    
    <?php endforeach;
    wp_reset_postdata();?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘get_posts — show category title?’ is closed to new replies.