bbPress

Simple, Fast, Elegant

bbPress support forums » Themes

Detecting whether a post is the first in a topic

(5 posts)
  • Started 6 days ago by Lookfab
  • Latest reply from Lookfab
  • This topic is not resolved

Tags:

  1. 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.

    Posted 6 days ago #
  2. bobbyh
    Member

    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.

    Posted 5 days ago #
  3. 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?

    Posted 3 days ago #
  4. bobbyh
    Member

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

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

    Posted 3 days ago #
  5. Yes, this does the trick. Thanks very much!

    Posted 2 days ago #

RSS feed for this topic

Reply

You must log in to post.

Code is Poetry.