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

  • Home
  • SEARCH
  • 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 7875527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:59:50+00:00 2026-06-03T02:59:50+00:00

<?php if ( have_posts() ) : ?> <?php $count = 1; $featuredPosts = 9;

  • 0
<?php if ( have_posts() ) : ?>

<?php
$count = 1;
$featuredPosts = 9;
query_posts('showposts=19');
?>

<div class="articleTile column_3">

<?php while ( have_posts() ) : the_post(); ?>

    <?php if($count > $featuredPosts) : ?> 

        <!--change class to articleList column_2-->

    <?php endif; ?>

<div class="column">

    <?php get_template_part( 'content', 'featured' ); ?>

    <!-- #post-<?php the_ID(); ?> -->

</div>

<?php
$count = $count ++;
endwhile;
?>

</div>

How would I go about targeting the <div class="articleTile column_3"> element and changing its class when the count variable reaches 10?

EDIT: I’m an idiot sorry.

I’ve managed to do it with:

<?php if ( have_posts() ) : ?>

<?php
$count = 1;
$featuredPosts = 9;
query_posts('showposts=19');
?>

<div class="articleTile column_3">

<?php while ( have_posts() ) : the_post(); ?>

    <?php if($count == $featuredPosts + 1) : ?>

    <?php echo $count ?>
        </div>
        <div class="articleList column_2">

    <?php endif; ?>

<div class="column">
<?php echo $count ?>
    <?php get_template_part( 'content', 'featured' ); ?>

    <!-- #post-<?php the_ID(); ?> -->

</div>

<?php
$count = $count +1;
endwhile;
?>

</div>

My original way wouldn’t have worked anyway without a 2nd element with a different class. My apologies. Thanks for the fast responses they helped point me in the right direction.

  • 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-06-03T02:59:51+00:00Added an answer on June 3, 2026 at 2:59 am

    Isn’t it smarter to just run the a loop first to check what the total count is gonna be and then use it to set the right class?

    Something like this perhaps? :

    <?php if ( have_posts() ) : ?>
    
    <?php
    $count = 1;
    $count_posts = 1;
    $featuredPosts = 9;
    $class = 'column_3';
    
    query_posts('showposts=19');
    
    /* Run loop */
    while ( have_posts() ) : the_post(); 
    
        $count_posts = $count_posts ++;
    endwhile;
    
    if ($count_posts > $featuredPosts) { $class = 'column_2'; }
    
    ?>
    
    <div class="articleTile <? echo $class; ?>">
    
    <?php while ( have_posts() ) : the_post(); ?>
    
    
    
    <div class="column">
    
        <?php get_template_part( 'content', 'featured' ); ?>
    
        <!-- #post-<?php the_ID(); ?> -->
    
    </div>
    
    <?php
    $count = $count ++;
    endwhile;
    ?>
    
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<?php $i = 1; $y = 5; ?> <?php while (have_posts()) : the_post(); ?>
I have the following code: <form action= method=POST> <?php $count = isset($_POST['count']) ? $_POST['count']
This is a PHP problem in WordPress while using a custom theme options panel.
I have an application that posts data to a php script through jquery's ajax
I currently have a problem within PHP where I want to sort these posts
I have a post html form, and the action is index.php, which is the
I have this PHP code in a loop for every post on the admin
I have a PHP script that I'm calling with the .post() function in jQuery.
I have a PHP script on a server <?php // retrieve POST vars $comment
In a php-script i have a form, method is post, action-attribute is empty, which

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.