Forums

[resolved] Styling fist post (2 posts)

  1. jimmytubbs
    Member
    Posted 2 years ago #

    I want to style every first post that comes on my main page.

    What is the <?php
    code for that
    ?

  2. Mark / t31os
    Moderator
    Posted 2 years ago #

    Find
    <?php while(have_posts()) : the_post(); ?>
    Replace with...
    <?php $countposts = 0; while(have_posts()) : the_post(); $countposts++; ?>

    Then wherever you want to do something different...

    <?php if($countposts == 1) {
      // YOUR CODE
    } ?>

    So for example, lets say you have the following piece of HTML...
    <div class="example">
    And you wanted to add a class when it's the first post, it would then become.
    <div class="example<?php if($countposts == 1) { ?> secondclass<?php } ?>">

    Your HTML then becomes..
    <div class="example secondclass">

    All you need then do is add a CSS definition for that second class in your stylesheet.
    Example:

    .secondclass {
      background-color: #000;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.