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

SWORD Studios info at swordstudios.net
Mon Apr 4 03:48:51 UTC 2011


Thanks Otto that's exactly what I did and it's up and running here:
http://swordstudios.net/hello-world/

On Sun, Apr 3, 2011 at 11:31 PM, Otto <otto at ottodestruct.com> wrote:

> On Sun, Apr 3, 2011 at 10:21 PM, Matt Martz <matt at sivel.net> wrote:
> > On Sun, Apr 3, 2011 at 10:19 PM, SWORD Studios <info at swordstudios.net>
> wrote:
> >>
> >> Haha, wow, I should be going to bed when that happens (late night).
> Thanks
> >> that immediately fixed it.
> >> Now the comments are coming in above the content in the post.  I have a
> few
> >> paragraphs of content then at the bottom is the shortcode.  However when
> you
> >> view the post it has the comments above everything else.  Any idea why?
> >
> > For starters shortcodes need to return, and comments_template does an
> > include() which is basically echoing.  Likely the only way you will
> > get it to work is to output buffer it, put the output into a var and
> > then add it to the return.  Of course this will increase memory usage,
> > and blah blah blah...Don't feel like typing any more, but you likely
> > know of the down falls of output buffering, but it is likely your only
> > option here.
>
> Right, trying to call comments_template inside the shortcode just
> isn't going to work.
>
> Instead, why not have the comments shortcode set a global variable,
> then base your call to comments_template later in the code based on
> that global variable. Like this:
>
> function sword_comment_shortcode($sword_comment_atts) {
> global $sword_do_comments;
> $sword_do_comments = true;
> }
> add_shortcode('comments-shareit', 'sword_comment_shortcode');
>
> ... later ...
>
> if ($sword_do_comments) {
>  comments_template();
> }
>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
*Jesse Friedman*   Founder / Lead Developer
*SWORD Studios* | 508.50.SWORD info at swordstudios.net
swordstudios.net @professor <http://twitter.com/professor>


More information about the wp-hackers mailing list