0

I am trying to put several queries in a shortcode so that I can call them in a page instead of using custom templates. I got my query going but I only see some of the content on the page. The image shows up, the text shows up but none of the html markup is showing up. Is there a Wordpress function that I need to pass this all through so it doesn't strip the HTML?

function band_query($atts) { ?>
    <ul>
    <?php                           
    extract(shortcode_atts(array(
        "category" => '',
        "number" => ''
    ), $atts));

    $band = new WP_Query( array(
        'category_name' => $category,
        'posts_per_page' => $number
    ));
    $output = '';
    // The Loop
    if( $band->have_posts()):
        $output .= '<div id="band_bio">';
        $output .= '<ul>';
        while ( $band->have_posts() ) : $band->the_post(); 
            $output .= '<li>';
            $output .= '<figure>' . the_post_thumbnail('band', array('class' => 'left marg_right1')) .' </figure>';
            if ( has_excerpt()){
                $output .= the_excerpt();
            } else {
                $output .= the_content(); 
            }                                   
            $output .= '<div class="relative"><a href=' .the_permalink() . 'class="button1">  <span></span><strong>Read More</strong></a></div>';
            $output .= '</li>';
        endwhile; 
    endif;
    wp_reset_postdata();
    $output .= '</ul>';

    $output .= '
    </div>
    <a href="#" class="prev"></a>

    <a href="#" class="next"></a>

    $output = apply_filters('the_content', $content);   
    return $output;

}
add_shortcode("band_page", "band_query");
3
  • 1
    You forgot a closing quote. Look at the output of the syntax highlighter.
    – fuxia
    Apr 20 '13 at 22:52
  • And the first <ul> is outside of $output. Also, using a nice indentation in the code makes it easier to read and debug.
    – brasofilo
    Apr 21 '13 at 0:12
  • my syntax highlighter doesn't show a missing anything. I don't see one either. As far as the indenting. Is there a trick to getting it to work on this site? I do indent my code and then I have to spend 10 minutes trying to make it look readable here. Eventually, I get it close enough and post it. It loses all formatting when I copy it over
    – Jamie
    Apr 21 '13 at 3:15
4

When you are constructing the $output variable, you need to consider

get_the_post_thumbnail()
get_the_excerpt()
get_the_content()
get_permalink()

that return the values instead of

the_post_thumbnail()
the_excerpt()
the_content()
the_permalink()

that echo the values.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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