Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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; ?> 
share|improve this question
    
What do_shortcode line? –  s_ha_dum Sep 25 '13 at 3:30
    
Ahhh... sorry about that. Updated! –  TechyDude Sep 25 '13 at 3:33

1 Answer 1

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.

$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) { 
  while ( $the_query->have_posts() ) { 
    $the_query->the_post(); 
    $post_slug = $post->post_name;
    echo do_shortcode("[anything_slides cat=".$post_slug."]");
  }
}

But there is really no need to set the variable at all. Just use $post->post_name.

share|improve this answer
    
Thanks for the answer @s-ha-dum! I updated my code with that, except no luck. The page renders 7 posts (I have 7 posts in that category), except all of the same posts display the post title and description of the PAGE that I set the template to. –  TechyDude Sep 25 '13 at 3:50
    
Ok basically, something interesting is happening. When I post the do_shortcode for the slider AFTER the post title and content, everything works (the slider only appears once though), but if I post do_shortcode above the title and content, then the issue I mentioned above occurs –  TechyDude Sep 25 '13 at 3:59
    
There is information missing. Edit the question with the shortcode callback. –  s_ha_dum Sep 25 '13 at 13:56
    
I added all of the template. First I run a query to display all of the post titles as links. Then I display a query to grab the post info: slider, content and title. If I put the shortcode call above the title and content, then ALL of the posts appear with the title and content from the PAGE that I apply the content to. At the top of the template I call <h4><?php echo $page_object->post_content; ?></h4> the content from the page which the template is applied to, and for some reason the query gets weird and replaces the post content with that description and title. –  TechyDude Sep 25 '13 at 14:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.