Im using a cool plugin called "wp ajax random posts". It basically lets me call a function into a template that can auto refresh a loop of posts. It works great until I tried to change the loop structure inside the function. My posts have embedded youtube videos so I set it up so the section was only calling the video and its ratings. Originally it was just for a title and that worked fine but when I added the video it returns a second post under the original that was suppose to dissapear. From there it refreshes the bottom video like normal which boggles my mind. Here's the original function and then the modified one. Can someone point out why this is happening?
function WARP_Random_posts($args=''){
$defargs=array('number' => 8, 'cmtcount' => 0, 'excerpt' => 0, 'length' => 100, 'auto' => 0, 'time' => 60);
$args = wp_parse_args($args, $defargs);$output='';$number=$args['number'];
query_posts("showposts=$number&orderby=rand&cat=3");
if(have_posts()){
while (have_posts()) :the_post();
$output.='<li id="random-post-'.get_the_ID().'" class="random-post"><div class="random-post-title"><a title="'.get_the_title().'" class="random-post-link" href="'.get_permalink().'">'.get_the_title().'</a>';
if($args['cmtcount']!=0)$output.='('.get_comments_number().')';
$output.='</div>';
if($args['excerpt']!=0)$output.='<div class="random-post-excerpt">'.WARP_Random_posts_substr(strip_tags(get_the_content()),(int)$args['length']).'</div>';;
$output.='</li>';
endwhile;
$output.='<li id="random-post-more" class="random-post" style="text-align:center"><div><a style="width:100%;height:100%" href="javascript:;" onclick="WARP_.get_random_posts(\'number='.$args['number'].'&cmtcount='.$args['cmtcount'].'&excerpt='.$args['excerpt'].'&length='.$args['length'].'&auto='.$args['auto'].'&time='.$args['time'].'\')">'.__('Refresh', 'WP-Ajax-Random-Posts').'</a>'.($args['auto']?': <span id="refreshTime">'.$args['time'].'</span>':'').'</div></li>';
return $output;
}else{
WARP__showErr(__('There is no post.','WP-Ajax-Random-Posts'));
}
}
modified...
function WARP_Random_posts($args=''){
$defargs=array('number' => 8, 'cmtcount' => 0, 'excerpt' => 0, 'length' => 100, 'auto' => 0, 'time' => 60);
$args = wp_parse_args($args, $defargs);$output='';$number=$args['number'];
query_posts("showposts=$number&orderby=rand&cat=3");
if(have_posts()){
while (have_posts()) :the_post();
$name = get_post_meta(get_the_ID(),'video_code',true);
youtube_video_embed( $name, 'autoplay=on&width=640&height=376' );
if(function_exists('the_ratings')) { the_ratings(); };
if($args['cmtcount']!=0)$output.='('.get_comments_number().')';
$output.='</div>';
if($args['excerpt']!=0)$output.='<div class="random-post- excerpt">'.WARP_Random_posts_substr(strip_tags(get_the_content()),(int)$args['length']).'</div>';;
$output.='</li>';
endwhile;
$output.='<li id="random-post-more" class="random-post" style="text-align:center"><div><a style="width:100%;height:100%" href="javascript:;" onclick="WARP_.get_random_posts(\'number='.$args['number'].'&cmtcount='.$args['cmtcount'].'&excerpt='.$args['excerpt'].'&length='.$args['length'].'&auto='.$args['auto'].'&time='.$args['time'].'\')">'.__('Refresh', 'WP-Ajax-Random-Posts').'</a>'.($args['auto']?': <span id="refreshTime">'.$args['time'].'</span>':'').'</div></li>';
return $output;
}else{
WARP__showErr(__('There is no post.','WP-Ajax-Random-Posts'));
}
}