[wp-hackers] Shortcode to call comments_template();

Matt Martz matt at sivel.net
Mon Apr 4 03:09:43 UTC 2011


On Sun, Apr 3, 2011 at 10:05 PM, SWORD Studios <info at swordstudios.net> wrote:
> I'm attempting to call the comments_template(); function in a shortcode.
> Basically I want to call the comments template ONLY on a certain posts.
> Below is the shortcode function I wrote.  Everything works but the
> comments_template.
>
>
> function sword_comment_shortcode($sword_comment_atts) {
>  return '<h2 class="ltcol tk-league-gothic">I know you thought this was
> great, others will too.</h2>
>                   <article class="rtcol" ><span
> class=\'st_facebook_vcount\' st_title=\'{TITLE}\' st_url=\'{URL}\'
> displayText=\'share\'></span><span class=\'st_twitter_vcount\'
> st_title=\'{TITLE}\' st_url=\'{URL}\' displayText=\'share\'></span><span
> class=\'st_linkedin_vcount\' st_title=\'{TITLE}\' st_url=\'{URL}\'
> displayText=\'share\'></span>
>                            </article>
>                        <div class="clear"></div>
>                         <h2 class="ltcol tk-league-gothic">Share Your
> Thoughts!</h2>
>                   <article class="rtcol" >';
>
>  comments_template();
>
>  return '</article>
>  <div class="clear"></div>';
>
>  }
>  add_shortcode('comments-shareit', 'sword_comment_shortcode');

Well first things first, your callback function is going to basically
exit after the first return and never meet the comments_template()
call, since you are doing a return before you run that function.

-- 
Matt Martz
matt at sivel.net
http://sivel.net/


More information about the wp-hackers mailing list