Thanks John, I really appreciate all your help, I'll do that! :)
Printable View
Thanks John, I really appreciate all your help, I'll do that! :)
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-->
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.
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.
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!!
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.
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! :)
Non-javascript users will see the un-shuffled list.
Add this script to the head of the page:
Put it anywhere after this line: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>
Tested and works in a local mock up of the page.Code:<script type="text/javascript" src="http://www.monaghanweddings.com/wp-content/themes/monaghan-weddings/carousel/lib/jquery-1.4.2.min.js"></script>
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>
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! :)
I will PM my email address. However, you can always click the last link in my signature below: