[wp-hackers] Comments outside the main loop

Guy Leech guyleech at gmail.com
Sat May 5 00:08:30 GMT 2007


Yes, I had a poke around in comments.php, and saw how it does it. All's
working fine and dandy now, I'm just querying the database in my header and
going from there.

Thanks
 - Guy

On 5/5/07, Otto <otto at ottodestruct.com> wrote:
>
> What you've overlooked is that $comments is not setup until you
> actually get to the comments.php file.
>
> comments_template() does more than just include comments.php. It
> actually get the comments from the database, builds the $comments
> array, and *then* includes comments.php.
>
> So until you call comments_template(), $comments is empty.
>
>
> On 5/3/07, Guy Leech <guyleech at gmail.com> wrote:
> > Continuing on from my variable content width, I'm now trying to extend
> the
> > width based on the number of comments too. However, I've been having a
> bunch
> > of difficulties - basically, I can't loop through the comments outside
> of
> > the comments.php file.
> >
> > I've tried looping through comments in the header, in the single.php,
> tried
> > using globals and includes to track them, and I've gotten nowhere. I
> want to
> > count the number of paragraphs in the comments, and change a stylesheet
> > variable based on that. The code that I'm using looks like this:
> >
> > if ( have_posts()) {
> > >             while ( have_posts()) {
> > >                 the_post();
> > >                 $p = count_paragraphs(get_the_content());
> > >                 if ( is_home())
> > >                 {
> > >                     $p = count_paragraphs(get_the_excerpt());
> > >                 }
> > >             }
> > >         }
> >
> >
> >
> > I want to include a section in there that looks like this:
> >
> > > if ( $comments )
> > >             {
> > >                 foreach ( $comments as $comment )
> > >                 {
> > >                     $p += count_paragraphs(get_comment_text());
> > >                 }
> > >             }
> >
> >
> > This code is in my header.php. $p is later sent to my stylesheet as a
> URL
> > query, which then calculates the width of my content based off that.
> >
> > So, if anyone has brilliant ideas, or something I've overlooked, fire
> away.
> >  - Guy
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list