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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:58:28+00:00 2026-05-13T16:58:28+00:00

I think (hope) my question is simpler than how I’ve phrased it, but this

  • 0

I think (hope) my question is simpler than how I’ve phrased it, but this is also why I’m coming up empty on Google. It’s similar to this, but I need to handle some HTML with it and am a little unclear: Random image display

In the sidebar of my WordPress install I have two images in this order:

<a href="http://www.link1.tld"><img src="files/image1.jpg" border="0" /></a>
<a href="http://www.link2.tld"><img src="files/image2.jpg" border="0" /></a>

What’s the easiest way to accomplish rotating this order when the page is refreshed (so that the order will be image2 / image1)? And upon next refresh, go back to image1 / image2?

  • 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-13T16:58:29+00:00Added an answer on May 13, 2026 at 4:58 pm

    To accomplish this you’ll need to store a view counter in a cookie with the user and then display based on that counter:

    session_start();
    if(!isset($_SESSION['views'])) {
      $_SESSION['views'] = 0;
    }
    else {
      $_SESSION['views']++;
    }
    

    and then to display:

    <?php if($_SESSION['views'] % 2 == 0): ?>
    <a href="http://www.link1.tld"><img src="files/image1.jpg" border="0" /></a>
    <? endif; ?>
    <a href="http://www.link2.tld"><img src="files/image2.jpg" border="0" /></a>
    <?php if($_SESSION['views'] % 2 == 1): ?>
    <a href="http://www.link1.tld"><img src="files/image1.jpg" border="0" /></a>
    <? endif; ?>
    

    If the view counter is even it will print image1 first. If it’s odd it’ll print it second.

    Scaling this to more than two images could be done like this:

    // map of images to URLs
    $images = array(
      'image1.jpg' => 'http://www.link1.tld',
      'image2.jpg' => 'http://www.link2.tld',
      'image3.jpg' => 'http://www.link3.tld',
      'image4.jpg' => 'http://www.link4.tld',
    );
    
    // reorder the list of images based on the current view count
    $ordered = array_merge(array_slice($images, $_SESSION['views'] % count($images)), array_slice($images, 0, $_SESSION['views'] % count($images)));
    

    and then the display just loops through the ordered list:

    <?php foreach($ordered as $image => $url): ?>
    <a href="<?php echo $url; ?>"><img src="files/<?php echo $image; ?>" border="0" /></a>
    <?php endforeach; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[I hope that this question is not too broad, I think that the subject
I think I already know the answer to this one, but i hope maybe
I hope this is a quite easy question but I couldn't understand why is
I hope this question is still on topic, but recently I found a key-value
This is my first question here, but I hope I will get a lot
This is a very simple, probably too simple question but I'm afraid my limited
I hope I can make this question clear enough. I'm looking to put a
I posted a question similar to this earlier, however, after thinking about it and
Hi I hope this question conforms to community guidelines. While working in Matlab I'd
I hope I'm not being too long winded in this question, I just want

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.