[wp-hackers] Comments outside the main loop
Guy Leech
guyleech at gmail.com
Fri May 4 02:36:25 GMT 2007
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
More information about the wp-hackers
mailing list