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 9228395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:18:49+00:00 2026-06-18T05:18:49+00:00

I have code for my carousel in WordPress <?php $the_query = new WP_Query(array( ‘category_name’

  • 0

I have code for my carousel in WordPress

<?php 
    $the_query = new WP_Query(array(
     'category_name' => 'home-slider', 
     'posts_per_page' => 5  
    )); 
    while ( $the_query->have_posts() ) : 
    $the_query->the_post();
?>
<div class="sl-slide">
 <?php the_post_thumbnail('large');?>
 <div class="sl-slide-inner">
 <?php the_title();?>
 <?php the_excerpt();?>
</div>
</div>
<?php 
endwhile; 
wp_reset_postdata();
?>

I display 5 post in carousel. I want basic If-else statment where for every page I create static variable. for instance:.

if (post == 1) {
 $aka = 7;
} else if (post == 2) {
 $aka = 8;
} else if (post == 3) {
 $aka = 9;
} .. and etc.

I can’t figure it out how to implement it in WP, how to say which post is now?

  • 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-18T05:18:51+00:00Added an answer on June 18, 2026 at 5:18 am

    When you are in WP_Query while-loop, you can access current post by $post variable, which has standard post object.
    Just don’t forget to have following row before the loop:

    <?php 
        global $post;
        $the_query = new WP_Query(array(
         'category_name' => 'home-slider', 
         'posts_per_page' => 5  
        )); 
        while ( $the_query->have_posts() ) : 
        $the_query->the_post();
    ?>
    <div class="sl-slide">
    <?php
    if ($post->ID == 1) {
     $aka = 7;
    } else if ($post->ID == 2) {
     $aka = 8;
    } else if ($post->ID == 3) {
     $aka = 9;
    }
    ?>
     <?php the_post_thumbnail('large');?>
     <div class="sl-slide-inner">
     <?php the_title();?>
     <?php the_excerpt();?>
    </div>
    </div>
    <?php 
    endwhile; 
    wp_reset_postdata();
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to jQuery. I have the following code: jQuery(document).ready(function() { jQuery('#carousel').jcarousel(); });
I have some php code below, where I'm using foreach. <div class=carousel-inner> <?php if(count($items)):
I have smooth-scroll jQuery code that is completing with my bootstrap carousel jQuery code
I have this javascript code: $(function(){ var currentCarouselItem = 1; //set carousel to first
I have the following code: HTML: <div class=sectionInner><div class=carousel></div></div> <div class=sectionInner></div> <div class=sectionInner></div> <div
I have the following code (function($) { // carousel var Carousel = { settings:
I'll even share my code with you! Basically, I have a carousel that I
I have a carousel slider, which have three static dots in the corner, one
I have code that generates a List<string[]> variable but can't quite figure out how
I have code like this in my view model: function ChatListViewModel(chats) { var self

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.