Horje
Generate Thumbnails of Category - Wordpress Solution
[Solved] - Generate Thumbnails of Category - Wordpress Solution
Try following codes
Hello, On single post pages we would like to display thumbnails of other posts in the same category. The thumbnail is a custom field value called "thumbnail" which every post has. In the single post .php is this code:

<?php $theme_options = get_option('Grace'); ?>
		<?php if (!isset($theme_options["autothumb"]) || $theme_options["autothumb"] == "timthumbon") { 
		    include (TEMPLATEPATH . '/includes/postautothumbson.php'); 
		    } 
		    else if (!isset($theme_options["autothumb"]) || $theme_options["autothumb"] == "timthumboff") { 
		        include (TEMPLATEPATH . '/includes/postautothumbsoff.php'); 
		} ?>				
That calls to "postautothumbsoff.php" in this case since automatic thumbnails are turned off. In "postautothumbsoff.php" the code is the following:

<?php

			$i = 1; // set variable used to control which style is applied to thumbnail

			  if (have_posts()) : while (have_posts()) : the_post(); // check if there are any posts

				if ($i % 2 == 0) { // check if $i is divisible by 2 with no remainder then apply style to variable $c
       			  $c = ' class="alt"';
    			  } else {
        			$c = '';
   					}
			
			$post_id = $post->ID;
			$single = true;
							
			$key = thumbnail;
			$thumbnail_value = get_post_meta($post_id, $key, $single);
			
			if ( $thumbnail_value ) : // retreive thumbnail custom field value 
			 
			?>

				<li<?php echo $c ?>>
				  <a href="<?php the_permalink() ?>" class="thumbhover">
				    <img src="<?php echo $thumbnail_value; ?>" alt="<?php the_title('','',False); ?> "/> 
				  </a><div class="luisthumb">
                             <?php
{ $luisthumb = get_post_meta
($post->ID, 'luisthumb', $single = true);
if($luisthumb !== '') echo $luisthumb;} ?>
</div>
				</li>

				<?php $i++; else :?>
				
				<li<?php echo $c ?>><a href="<?php the_permalink() ?>"><strong><?php the_title(); ?></strong></a><br/><?php the_excerpt(); ?></li>
				
				<?php $i++; endif; endwhile; endif; ?>

Currently it is not working. It only shows the thumbnail of the single post. Instead it should show all thumbnails of the posts category. The link to a single post is: http://piersrueb.com/blog/archives/96 The link to the categories page is: http://piersrueb.com/blog/archives/category/commercials All the thumbnails there displayed should also show up on the single post pages. Thank you for your help. replace
$key = thumbnail;
$thumbnail_value = get_post_meta($post_id, $key, $single);
by
$key = 'thumbnail';
$thumbnail_value = get_post_meta(get_the_ID(), $key, $single);
var_dump($thumbnail_value);
what the output on a category php? and is category php has this loop insided? Thank you for your quick reply. I tried what you said and go the following error on the front-end: Parse error: syntax error, unexpected T_IF in /home/piersru1/public_html/blog/wp-content/themes/grace/includes/postautothumbsoff.php on line 21 Regarding your questions: i have no answer because i am too ignorant of php. If I understand correctly its concerning my category php. Here is the category php code:
<?php get_header();
  
  if (have_posts()) : ?>
  
	<div id="columnleft"> <!-- columnleft -->
	
	  <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
 	  <?php /* If this is a category archive */ if (is_category()) { ?>
		<h2 class="pagetitle"><?php single_cat_title(); ?> Showcase</h2>
		<p> <?php echo category_description( $category ); ?> <p>        
        <div class="sexy"><?php if(function_exists('selfserv_sexy')) { selfserv_sexy(); } ?></div>
 	  <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
		<h2 class="pagetitle">Photos Tagged &#8216;<?php single_tag_title(); ?>&#8217;</h2>
		<p>These are all of the photos tagged &#8216;<?php single_tag_title(); ?>&#8217;.</p>
 	  <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
		<h2 class="pagetitle">Archive for <?php the_time('F jS, Y'); ?></h2>
		<p>These are all of the photos from <?php the_time('F jS, Y'); ?>.</p>		
 	  <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
		<h2 class="pagetitle">Archive for <?php the_time('F, Y'); ?></h2>
		<p>These are all of the photos from <?php the_time('F, Y'); ?>.</p>		
 	  <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
		<h2 class="pagetitle">Archive for <?php the_time('Y'); ?></h2>
		<p>These are all of the photos from <?php the_time('Y'); ?>.</p>				
	  <?php /* If this is an author archive */ } elseif (is_author()) { ?>
		<h2 class="pagetitle">Author Archive</h2>
		<p>These are all of the photos added by <?php the_author(); ?>.</p>				
 	  <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
		<h2 class="pagetitle"><?php bloginfo('name'); ?> Gallery Archives</h2>
		<p>These are all of the photos from the <?php bloginfo('name'); ?> gallery archives.</p>
 	  <?php } ?>
	  
  	  <p class="clearall">&nbsp;</p>	
		
	</div> <!-- columnleft -->
	
	<div id="columnright"> <!-- columnright -->
	  

      
      <ul id="latestworkgallery">

		<?php $theme_options = get_option('Grace'); ?>
		<?php if (!isset($theme_options["autothumb"]) || $theme_options["autothumb"] == "timthumbon") { 
		    include (TEMPLATEPATH . '/includes/autothumbson.php'); 
		    } 
		    else if (!isset($theme_options["autothumb"]) || $theme_options["autothumb"] == "timthumboff") { 
		        include (TEMPLATEPATH . '/includes/autothumbsoff.php'); 
		} ?>
	  
	  </ul>

	  <div class="clearall">&nbsp;</div>
	  
	  
		<p class="postnavigation">
			<?php next_posts_link('<span class="previouspostbutton">&nbsp;</span>') ?> <?php previous_posts_link('<span class="nextpostbutton">&nbsp;</span>') ?>
		</p>
	

	</div> <!-- columnright -->
	
	<p class="clearall">&nbsp;</p>
	
	 <?php endif; ?>	

  </div>  <!-- content -->
  
<?php get_footer(); ?> 
Does that help? let me check the category.php meanwhile check the code at main answer witch relates to the (after var dumpsemicollon).i think you have cpy my code with error before i had change it. btw. autothumbsoff.php and postautothumbsoff.php is the same file. I just duplicated it to be able to change the thumbnail generation on the single posts and the archives seperately. I tried your code again and this time it showed the thumbnail as before but put this line directly above the thumbnail:
string(73) "http://piersrueb.com/blog/wp-content/uploads/2010/07/timthumb-2.php_1.png" 
thank you for your help! And its show you this code only on single.php only? yes. your latest code is online now. http://piersrueb.com/blog/archives/63 thanks. let me write you a code of new loop for single.php wait a 5 minutes. cheers can you insert my code

	// its actualy array of the categories but we are taking only girst one
	$cat  = array_shift(get_the_category($post->ID));
	$params = array(
		'cat' => $cat->term_id,
		'showposts' => 6,
	);
	//showposts related to the numebr of the posts that shoueld be displayed be runned
	query_posts($params);
after this one (of your single.php)
  <ul id="latestworkgallery">
check the link on previous post. its showing it as text? is a php tag missing? sorry if this is a stupid question. It now reads:
 <h2>Featured</h2>
    
    	  <ul id="latestworkgallery">	
          
          // its actualy array of the categories but we are taking only girst one

	$cat  = array_shift(get_the_category($post->ID));

	$params = array(

		'cat' => $cat->term_id,

		'showposts' => 6,

	);

	//showposts related to the numebr of the posts that shoueld be displayed be runned
	query_posts($params);			
				
		<?php $theme_options = get_option('Grace'); ?>
		<?php if (!isset($theme_options["autothumb"]) || $theme_options["autothumb"] == "timthumbon") { 
		    include (TEMPLATEPATH . '/includes/postautothumbson.php'); 
		    } 
		    else if (!isset($theme_options["autothumb"]) || $theme_options["autothumb"] == "timthumboff") { 
		        include (TEMPLATEPATH . '/includes/postautothumbsoff.php'); 
		} ?>				
	  
	  </ul>
      	</div> <!-- columnright -->
sorry. you should wrap it by php tags

<?php
	// its actualy array of the categories but we are taking only girst one

	$cat  = array_shift(get_the_category($post->ID));

	$params = array(

		'cat' => $cat->term_id,

		'showposts' => 6,

	);

	//showposts related to the numebr of the posts that shoueld be displayed be runned

	query_posts($params);
?>
// once again sorry, its normaly for me to write php code without php tags... yes! its working. nearly. look at the link:[[LINK href="http://piersrueb.com/blog/archives/63"]]http://piersrueb.com/blog/archives/63[[/LINK]] it now shows the url of the pic adn something with "string" above it. the thumbs show though. any ideas? thank you just delete the var_dump string witch we have insert into this tread in this file postautothumbsoff.php should you need to, you can download both files at: www.piersrueb.com/foroleg.zip

Solution - 1

replace

$key = thumbnail;
$thumbnail_value = get_post_meta($post_id, $key, $single);
by
$key = 'thumbnail';
$thumbnail_value = get_post_meta(get_the_ID(), $key, $single);
var_dump($thumbnail_value);
what the output on a category php? and is category php has this loop insided?

Date: 2022-10-21 05:21:39
Category: Wordpress
More for You