Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 22

Thread: Random Image Rotation - Multiple Images

  1. #11
    Join Date
    Feb 2010
    Location
    Ireland
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Thanks John, I really appreciate all your help, I'll do that!

  2. #12
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Great. Now bear in mind I'm not sure if this will work, so keep a copy of what you have now. But I'd try this:

    PHP Code:
    <div id="supplier-directory-listing"> 
    <ul> 
                        <?php if (have_posts()) :
                        while (
    have_posts()) : the_post(); 
                        
    $some_posts[] = '<li><a target="_blank" href="' str_replace("\r"""get_the_content('')) . '">' $attr['title'] = $attr['alt'] = get_the_title() . the_post_thumbnail('supplier-img'$attr ) . '</a></li>';
                        endwhile; 
                        
    shuffle($some_posts);
                        echo 
    implode("\n"$some_posts);
                        endif; 
    wp_reset_query();?> 
                    </ul> 
                   </div><!-- // end #supplier-directory-listing-->
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    claireym (09-21-2011)

  4. #13
    Join Date
    Feb 2010
    Location
    Ireland
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Hi John, Thanks for that, I put it in but it still hasn't shuffled the ads... I again cleared my browsers cache and refreshed the page multiple times, still no movement at all. It's a bit of a head scratcher!! Thanks so much for the help though! I am thinking it may be a WordPress problem or something.

  5. #14
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Wow, I'm surprised it didn't cause an error! As long as the images show up, they should be shuffled. Problem could now just be what I mentioned before, small sample size.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #15
    Join Date
    Feb 2010
    Location
    Ireland
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    The images showed up, the only thing that changed was the spacing between them and their links weren't working. I did refresh multiple times but still nothing!

    I have found lots of scripts for shuffling but it talks about having whatever you are shuffling (e.g. posts) in an array. I am assuming I can't put mine in a array since I don't have names for these "posts"?? This is what I found: http://www.w3schools.com/php/func_array_shuffle.asp

    I could be totally wrong here... I really am relatively new to PHP!!

  7. #16
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You're not totally wrong. That was my general thinking as well, and I'm not all that much more advanced at PHP than you are. Also I have no experience with Wordpress.

    But I don't think you need an associative array (an array with names for the items it contains), as shuffle() says it works as well on an indexed array (an array with only items in it). In fact, it says that shuffle will remove the keys (names) of an associative array and you wind up with an indexed array anyway.

    The problem appears to me to get the posts into an array, shuffle it and then echo it to the page, either one at a time, or by imploding it as I did in my attempt there.

    But there may be a more elegant solution not involving array or involving an array of numbers as a guide to the process.

    Or the array idea we have may be fine, if so it just has to be implemented in a better fashion, one where the output markup survives and the array is actually shuffled.

    That's why I suggested opening a new thread, as it's unlikely others will chime in here once they see I'm working on it. And it will probably take someone more versed in PHP and Wordpress to work it out.

    A Wordpress forum might be able to help more too, if you can find one where they deal with the PHP side of operations like this.

    Javascript could be used though. I'm real good at that. If you want a Javascript solution, let me know.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. The Following User Says Thank You to jscheuer1 For This Useful Post:

    claireym (09-23-2011)

  9. #17
    Join Date
    Feb 2010
    Location
    Ireland
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Javascript would be brilliant John! I thought PHP would be the only way to go since the page is wrote in PHP but again I am not a great coder, more of a designer, so I am way in over my head already!

    If you can do something with Javascript, or any type of code, I would really appreciate that, otherwise I can open a new thread! Thankyou so much John, you're brilliant!

  10. #18
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Non-javascript users will see the un-shuffled list.

    Add this script to the head of the page:

    Code:
    <script type="text/javascript">
    jQuery('head').append('<style type="text/css">#supplier-directory-listing{visibility:hidden;}<\/style>');
    jQuery(function($){
    	var lis = [];
    	$('#supplier-directory-listing ul li').each(function(){
    		lis.push($(this).clone('true'));
    	});
    	lis.sort(function(){return 0.5 - Math.random()});
    	$('#supplier-directory-listing ul li').each(function(i){
    		$(this).replaceWith(lis[i]);
    	});
    	$('#supplier-directory-listing').css({visibility: 'visible'});
    });
    </script>
    Put it anywhere after this line:

    Code:
        <script type="text/javascript" src="http://www.monaghanweddings.com/wp-content/themes/monaghan-weddings/carousel/lib/jquery-1.4.2.min.js"></script>
    Tested and works in a local mock up of the page.

    If you want the 'Your Ad Here' to always appear last, use this version:

    Code:
    <script type="text/javascript">
    jQuery('head').append('<style type="text/css">#supplier-directory-listing{visibility:hidden;}<\/style>');
    jQuery(function($){
    	var lis = [];
    	$('#supplier-directory-listing ul li').each(function(){
    		lis.push($(this).clone('true'));
    	});
    	lis.pop();
    	lis.sort(function(){return 0.5 - Math.random()});
    	$('#supplier-directory-listing ul li').each(function(i){
    		if(lis[i]){
    			$(this).replaceWith(lis[i]);
    		}
    	});
    	$('#supplier-directory-listing').css({visibility: 'visible'});
    });
    </script>
    Last edited by jscheuer1; 09-23-2011 at 07:31 PM. Reason: add -If you want the 'You . . .
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  11. The Following User Says Thank You to jscheuer1 For This Useful Post:

    claireym (09-23-2011)

  12. #19
    Join Date
    Feb 2010
    Location
    Ireland
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    John, that has worked so so well, it is exactly what I was after! It is absolutly perfect!! A massive thankyou to you, I really appreciate your help! Just wondering if you have a PayPal account, if you do can you PM me your email address for it please? Thankyou so much!

  13. #20
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I will PM my email address. However, you can always click the last link in my signature below:
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •