Ok So I have a slider on my site and then under that there are 3 boxes. If a post has a featured image it will then show that picture on the slider and in the box if its the first post. Well when there is not post it shows a random picture from 8 different pictures. The problem I have is that the random picture that correlates to the first post is not the same in the slider and the box. Below is the code. How would I fix this? Code: if (have_posts()) : while (have_posts()) : the_post(); if($img_position == 'boxgrid'){ $thumb = get_the_post_thumbnail( $post->ID, 'post-thumbnail' ); $pattern= "/(?<=src=['|\"])[^'|\"]*?(?=['|\"])/i"; preg_match($pattern, $thumb, $thePath); $random_number = mt_rand(1, 8); if(!isset($thePath[0])){ $thePath[0] = get_template_directory_uri().'/images/slideshow/noftrdimg-'.$random_number.'.jpg'; } $tmp .= '<div class="boxgrid captionfull" style="background: transparent url('.$thePath[0].') repeat scroll 0 0; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; " title="'. get_the_title().'">'; $tmp .= '<div class="cover boxcaption">'; $tmp .= '<h3 style="padding-left:8px;"><a href="'. get_permalink().'" title="'. get_the_title().'">'. get_the_title().'</a></h3>'; $tmp .= '<p>'.substr(get_the_excerpt(), 0, 100).'</p>'; $tmp .= '</div>'; $tmp .= '</div>'; So that is the little boxes then here is for the slider. They are both in the same php file
Get a random image to show the same on two image sections
6
Ok So I have a slider on my site and then under that there are 3 boxes. If a post has a featured image it will then show that picture on the slider and in the box if its the first post. Well when there is not post it shows a random picture from 8 different pictures. The problem I have is that the random picture that correlates to the first post is not the same in the slider and the box. Below is the code. How would I fix this?
So that is the little boxes then here is for the slider. They are both in the same php file
Both you can see are using random number but they don't sync. So one will have picture 3 and the other picture 5, but I want them to both have say picture 6 for the each instance.
Thanks!
Code:
if (have_posts()) : while (have_posts()) : the_post();
if($img_position == 'boxgrid'){
$thumb = get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
$pattern= "/(?<=src=['|\"])[^'|\"]*?(?=['|\"])/i";
preg_match($pattern, $thumb, $thePath);
$random_number = mt_rand(1, 8);
if(!isset($thePath[0])){
$thePath[0] = get_template_directory_uri().'/images/slideshow/noftrdimg-'.$random_number.'.jpg';
}
$tmp .= '<div class="boxgrid captionfull" style="background: transparent url('.$thePath[0].') repeat scroll 0 0; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; " title="'. get_the_title().'">';
$tmp .= '<div class="cover boxcaption">';
$tmp .= '<h3 style="padding-left:8px;"><a href="'. get_permalink().'" title="'. get_the_title().'">'. get_the_title().'</a></h3>';
$tmp .= '<p>'.substr(get_the_excerpt(), 0, 100).'</p>';
$tmp .= '</div>';
$tmp .= '</div>'; Code:
while (have_posts()) : the_post();
$url = get_permalink();
$theme_fields = get_post_custom_values('my_url');
if(isset($theme_fields[0])){
$url = $theme_fields[0];
}
$tmp .='<div id="fragment-'.$id.'-'.$i.'" class="ui-tabs-panel">'. chr(13);
$random_number = mt_rand(1, 8);
if($width != '' || $height != ''){
if (get_the_post_thumbnail( $post->ID, array($width,$height),"" ) == '') { $ftrdimg = '<img src="'.get_template_directory_uri().'/images/slideshow/noftrdimg-'.$random_number.'.jpg" />'; } else { $ftrdimg = get_the_post_thumbnail( $post->ID, array($width,$height),"class={$reflect}" ); }
} else {
if (get_the_post_thumbnail( $post->ID, array(756,250),"" ) == '') { $ftrdimg = '<img src="'.get_template_directory_uri().'/images/slideshow/noftrdimg.jpg"/>'; } else { $ftrdimg = get_the_post_thumbnail( $post->ID, array(756,250),"class={$reflect}" ); }
}
$tmp .=' <a class="reflect" href="'.$url.'">'.$ftrdimg.'</a>'. chr(13); Thanks!
- KirkMcD
- footballbob06
- footballbob06
- SteveSRS
- [ 1 ] Thanks
- footballbob06
Next Topics on Trending Feed
-
6