Nivo Slider posts from category
-
I’m using the nivo slider to create a featured post section on my site.
I’m using the following code to gather the posted from a category named “Featured”
<?php global $post; $args = array( 'cat' => 3 ,'numberposts' => 5 ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); ?> <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> <?php the_excerpt(); ?> <?php endforeach; ?> <?php wp_reset_postdata(); ?>This does not display correctly. This shows all the posts on a single slide and creates 5 slides for the nivo slider.
If i change the code to:
<?php global $post; $args = array( 'cat' => 3 ,'numberposts' => 5 ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); ?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php endforeach; ?> <?php wp_reset_postdata(); ?>Then it shows the proper number of slides and shows one post per slide.
I assume my problem lies within the extra elements added of
<h3></h3>and<?php the_excerpt(); ?>The end result would have a single post per slide to display the title, the excerpt, and the featured image of each post along with a button/link to the full post.
Any help achieving this would be greatly appreciated! TIA
The topic ‘Nivo Slider posts from category’ is closed to new replies.