Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3960944
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:54:57+00:00 2026-05-20T02:54:57+00:00

I am trying to do an if/else-statement on my WP-template. But i can’t seem

  • 0

I am trying to do an if/else-statement on my WP-template. But i can’t seem to pick the right element.

I wan’t it to look for the latest post on the blog. I already added a script that add a class of .first to the latest post.

What im trying to do in dummy-php-language:

<?php
if ( class is .first) { do something to .first}
else () { do something to everything else }
?>

i’ve looked in the wp-documentation. But i can’t seem to find anything that will select “latest post“…

Thanks

Jonas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T02:54:57+00:00Added an answer on May 20, 2026 at 2:54 am

    A very simple solution would be to keep a count of the post you’re at, and do something if it’s the first. In the index.php, in the have_posts() loop:

    <?php if (have_posts()) : $count = 0; ?>
        <?php while (have_posts()) : the_post(); $count++; ?>
            <?php if($count ==1) ?>
                // do something to first
            <?php else ?>
                // do something to everything else
            <?php endif; ?>              
        <?php endwhile; else: ?>
    <?php endif; ?>  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write an IF ELSE statement to enable shipping, If user doesn't
I am trying to do an if-else statement for my CGPoints how would I
I am trying to write an if/else statement that will hide my .thumb <div>
I'm trying to do an else statement that would tell the user that the
I am trying to calculate this if/else statement through the JOption Message window. Prompt
I'm trying to achieve a cross-browser if/else statement. The issue is I'm checking the
I am trying to sum the total results in an if/else statement. so the
I'm trying to create an if-else statement, that will return different divs. I believe
I'm trying to create a simple stored procedure with an if else statement in
I am trying to write something comparable to an If, else if, else statement.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.