[Resolved] Post excerpt and taxonomy shortcode

Home Forums Support [Resolved] Post excerpt and taxonomy shortcode

Home Forums Support Post excerpt and taxonomy shortcode

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #482037
    David
    Staff
    Customer Support

    Hi Tom / Leo,

    i am working on some Post layouts and want to display excerpt and taxonomies using a shortcode. Currently being added to a left side bar. So far i have cobbled together the following PHP. But i am not sure how to return the content so it remains within the aside widget.

    function display_the_excerpt() {    
        if ( have_posts() ) :
            while ( have_posts() ) : the_post();
      		echo '<div class="aside-excerpt">';
            		the_excerpt(); 
      		echo '</div>';
      		echo '<div class="aside-categories">';  			
              		the_terms( $post->ID, 'category', '', '');
      		echo '</div>';
      		echo '<div class="aside-post-tags">';
      			the_terms( $post->ID, 'post_tag', '', '');
      		echo '</div>';
            endwhile;
        endif;
        }
    
    add_shortcode ( 'display_excerpt' , 'display_the_excerpt' );

    Any thoughts appreciated.

    David

    #482085
    Tom
    Lead Developer
    Lead Developer

    When echoing inside a shortcode, you need to use output buffering: https://codex.wordpress.org/Shortcode_API#Output

    #482335
    David
    Staff
    Customer Support

    Doh! Thanks and apologies Tom this is not the first time you have pointed me there.
    Too many late nights! I will go back to using the hooks!
    Much appreciated

    #482731
    Tom
    Lead Developer
    Lead Developer

    No problem! Glad I could help 🙂

    #482746
    David
    Staff
    Customer Support

    Honestly – sorry for wasting your time. Been there before with shortcodes. Hooked the output into the left-side bar, works like a treat!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.