While developing my WordPress application i have a requirement where i need to show some random posts and user should be provided a link where he/she can refresh the posts, this should be the part of home page and here is what i have done in home page so far
<div id="random-wrapper">
<h3>Random Posts</h3>
<div id="random-content" style="opacity: 1; display: block;">
<?php
$args1 = array( 'numberposts' => 12 ,'orderby' => 'rand');
global $post; //save the current post
$temp=$post;
$rand_posts1 = get_posts( $args1);
foreach( $rand_posts1 as $post ) ://yes this is required, we need $post in setup_postdata
setup_postdata($post); ?>
<?php $values = get_post_custom_values("Image");
if (isset($values[0])) { ?>
<span style="float:left; padding:0 0 10px;">
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" class="left">
<img src="<?php echo bloginfo('template_url'); ?>/scripts/timthumb.php?src=/<?php
$values = get_post_custom_values("Image"); echo $values[0]; ?>&w=80&h=80&zc=1&q=90"
alt="<?php the_title(); ?>" class="colabs-image" width="80px" height="80px" /></a>
</span>
<?php } ?>
<?php endforeach;
$post=$temp;//restore current page
?>
</div>
</div>
Above code is working fine, but i am not sure how can i refresh the above div so that it can fetch any other random posts to display in home page.
I know i can reload that using jQuery but for that i need to separate this to other page and than reload the page and i am not sure how this can be done in WordPress
Please suggest a way to achieve this functionality.
You could use an ajax call to the php file that is producing the content. Then take the response and refresh the div using its id. You might have to custom code a php file. You could basically reproduce the file to only output the content that you need. WordPress codex site has a lot of info on custom loops.