Skip to:
Content
Pages
Categories
Search
Top
Bottom

Detecting whether a post is the first in a topic

  • I want to format the first post differently to the rest in a thread. How do I detect whether the post currently being displayed using “post_text()” is the first one?

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Lookfab, here’s a slight tweak to the default kakumei topic.php theme file that should do what you want:

    <ol id="thread" start="<?php echo $list_start; ?>">

    <?php $i = 0; ?>

    <?php foreach ($posts as $bb_post) : $del_class = post_del_class(); ?>

    <li id="post-<?php post_id(); ?>"<?php if ($i == 0) { echo 'class="firstpost"'; } elseif !($i % 2) { echo ('class="alt"'); }?>>

    <?php bb_post_template(); ?>

    </li>

    <?php $i++; ?>

    <?php endforeach; ?>

    </ol>

    You can then style the class “firstpost” using CSS to make it stand out however you want…

    I didn’t test this, but I think it should work either by itself or with a tweak or two.

    Thanks bobbyh. I think this is what I am doing now, but the problem is that when the thread goes onto a second page, the first post on the second page gets class=”firstpost” too.

    Is there any other way to find out programmatically whether a post is the first one in a topic?

    Try this (inserted into the code I had above):

    <?php if ( ( $i == 0 ) && ( $page == 1 ) ) { echo 'class="firstpost"'; } elseif !($i % 2) { echo ('class="alt"'); }?>>

    Yes, this does the trick. Thanks very much!

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.