I am querying blog posts with a specific category (according to the template page slug, and want each post to output a slider, title and content. I’m using the wordpress plugin Anythingslider for WordPress. I am creating slides with the same category as the post slugs so that everything is automated and less copy and paste – however when I add the do_shortcode line, it duplicates the same post (for as many times as there are posts), instead of displaying EACH post!
Anyone have any ideas?
<?php
$args = array(
'post_type' => 'post',
'category_name' => $post->post_name,
'showposts' => 20,
);
$the_query = new WP_Query( $args );
$page_id = get_the_ID();
$page_object = get_page( $page_id ); ?>
<div class="project-column">
<h4><?php echo $page_object->post_content; ?></h4>
<h1>Title</h1>
<div id="navigation">
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<a href="#<?php echo $post->post_name; ?>"><?php the_title(); ?></a>
<?php endwhile; wp_reset_postdata(); ?>
<?php endif; ?>
</div>
</div>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div id="<?php echo $post->post_name; ?>"></div>
<div class="entry-container">
<div class="slider-container">
<?php $shortcode = do_shortcode('[anything_slides cat='.$post->post_name.']');
echo apply_filters('my_new_filter',$shortcode); ?>
</div>
<div class="project-column">
<h2><?php the_title(); ?></h2>
<?php echo the_content(); ?>
<hr>
</div>
</div>
<?php endwhile; wp_reset_postdata(); ?>
<?php endif; ?>
You set
$post_slug
outside the Loop, so the value never changes. You need to reset that inside the Loop so that it will be reset to each post in turn as the Loop progresses.But there is really no need to set the variable at all. Just use
$post->post_name
.