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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:03:58+00:00 2026-05-16T08:03:58+00:00

I am wanting to find out if the following is possible with PHP inside

  • 0

I am wanting to find out if the following is possible with PHP inside WordPress.

Basically if I have a directory in my site called “promos” that consists of 1 to many images (as these images can change), that I would like to read from within a PHP file into a carousel setup, i.e. something similar to this:

   <div class="scrollable" id="browsable">   

   <div class="items"> 

          <?php 
            $tot_images_from_promo_dir = [get_total_image_count_in_promos_dir]; 

            for ( $counter = 1; $counter <= $tot_images_from_promo_dir; $counter ++) {
                echo "<div>";
                    echo "<a href="#"><img src="[image_from_promo_directory]" /></a>
                echo "</div>";
            }
          ?>
    </div>
</div>

Basically want to somehow with php read total amount of images in my promo directory and then use this total in my loop max value and read each image file name in the promo directory and pass into my <img src=[image_name_from_promo_dir].

  • 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-16T08:03:59+00:00Added an answer on May 16, 2026 at 8:03 am

    Assuming that all files in the promos directory are images:

    <div class="scrollable" id="browsable">   
       <div class="items"> 
          <?php 
            if ($handle = opendir('./promos/')) {
    
                while (false !== ($file = readdir($handle))) {
                    echo "<div>";
                        echo "<a href='#'><img src='".$file."' /></a>";
                    echo "</div>";
                }
                closedir($handle);
            }
          ?>
        </div>
    </div>
    

    If, however, there are files in the directory that are not images, you would need to check that before showing it. The while loop would need to change to something like:

    while (false !== ($file = readdir($handle))) {
        if ((strpos($file, ".jpg")) || (strpos($file, ".gif"))) {
            echo "<div>";
                echo "<a href='#'><img src='".$file."' /></a>";
            echo "</div>";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model Rails model called Orders that has a type_id, location, and
I know, there are some similar questions to the following out there, but I
I have a window form application, and it has multiple threads running that would
I have a listings database. I also have a listings_attributes database that looks like
I am trying to work out the best approach for a data migration. I
I'm moving away from strict Android development and wanting to create iPhone applications. My
I have been programming in C/C++ for about five years and Python for three;
I just had a quick question as I'm still learning grails. I have a
I know the title is really unclear, so give me a moment :) I'm

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.