logo

$20
Generate Thumbnails of Category

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() ?>"><?php the_title(); ?></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.

attachment image View Attachment

Mathias Vagni | 07/24/10 at 12:39pm | Edit


(1) Possible Answers Submitted...

  • avatar
    Last edited:
    07/24/10
    5:20pm
    Oleg Butuzov says:

    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?

    Previous versions of this answer: 07/24/10 at 4:08pm | 07/24/10 at 4:22pm

    • 07/24/10 4:29pm

      Mathias Vagni says:

      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(); ?>

    • 07/24/10 4:29pm

      Mathias Vagni says:

      Does that help?

    • 07/24/10 4:32pm

      Oleg Butuzov says:

      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.

    • 07/24/10 4:37pm

      Mathias Vagni says:

      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" 


    • 07/24/10 4:37pm

      Mathias Vagni says:

      thank you for your help!

    • 07/24/10 4:40pm

      Oleg Butuzov says:

      And its show you this code only on single.php only?

    • 07/24/10 4:41pm

      Mathias Vagni says:

      yes. your latest code is online now.

      http://piersrueb.com/blog/archives/63

    • 07/24/10 4:44pm

      Oleg Butuzov says:

      thanks. let me write you a code of new loop for single.php wait a 5 minutes. cheers

    • 07/24/10 4:53pm

      Oleg Butuzov says:

      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">

    • 07/24/10 4:59pm

      Mathias Vagni says:

      check the link on previous post.

      its showing it as text? is a php tag missing? sorry if this is a stupid question.

    • 07/24/10 5:00pm

      Mathias Vagni says:

      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 -->

    • 07/24/10 5:05pm

      Oleg Butuzov says:

      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...

    • 07/24/10 5:15pm

      Mathias Vagni says:

      yes!

      its working. nearly.

      look at the link:http://piersrueb.com/blog/archives/63

      it now shows the url of the pic adn something with "string" above it.

      the thumbs show though.

      any ideas? thank you

    • 07/24/10 5:17pm

      Oleg Butuzov says:

      just delete the var_dump string witch we have insert into this tread in this file postautothumbsoff.php

    • 07/24/10 5:17pm

      Mathias Vagni says:

      should you need to, you can download both files at: www.piersrueb.com/foroleg.zip

    • 07/24/10 5:26pm

      Oleg Butuzov says:

      Attached Image

    • 07/24/10 5:32pm

      Mathias Vagni says:

      I just transfered you the money. It worked. Thank you.

      Also i asked you if you would like to send us an email at info@disengised.com

      We often need help on some little things like this and also some bigger problems.

      Send us a quote of your fees and some contact details and we'll get in touch!

      Thank you.

This question has expired.





Current status of this question: Completed