bbPress

Simple, Fast, Elegant

bbPress support forums » Themes

Setting a different css class for the first topic

(4 posts)
  • Started 1 year ago by Mirce
  • Latest reply from ear1grey
  • This topic is not resolved

Tags:

  1. Is there a way to set up a new css class for the first post in a topic? I am thinking at something like;

    if post_id = 1
    echo "some class"

    I am a PHP newbye and I am having problems implementing this...
    Thanx.

    Posted 1 year ago #
  2. A lazy short circuit solution which makes the first displayed entry in a loop appear different:

    $special="specialClass normalClass";
    for {
      echo ... class="$special" ...
      $special="normalClass";
    }
    Posted 1 year ago #
  3. Sounds difficult to set up:)
    I understand that I create a variable but how do I make it make the difference between the posts.

    I found a bb_is_first and I am thinking in using this one somehow.

    Posted 1 year ago #
  4. It doesn't have to know the difference. You set

    $special
    to be a special class before the loop, then the last thing you do in the loop is set
    $special
    to be something else. So the first time round the loop
    $special
    has it's original value, then at the end of the first loop it's value is changed (so it's no longer the initial value).

    The fact that the value is repeatedly reset to the other value is irrelevant (there is overhead in this, but it's comparable to calling a function each time round the loop to check for "is this the first item" and it has the advantage that it's not API specific.

    Posted 1 year ago #

RSS feed for this topic

Reply

You must log in to post.

Code is Poetry.