• Hi! I’m developing a site that uses categories quite a lot (see https://www.fhoto.se/nytest for a test site) and I’m trying to get a new front page working with thumbnails of one post from each category.

    I tagged a post in each category with ‘frontar’ and tried modifying the YAPB mosaic code found here: https://johannes.jarolim.com/blog/2008/07/24/your-own-photo-mosaic-page-with-wordpress-and-yapb/

    into this:

    <?php if (have_posts()): while (have_posts()): the_post(); ?>
    
      <?php global $post; ?>
    
    <?php 
    
      $photoblog_posts = get_posts('tag=frontar');
    
      $thumbConfig = array(
        'h=167',
        'q=100',
        'fltr[]=usm|60|0.5|0'
      );
    
    ?>
    
        <?php foreach($photoblog_posts as $photoblog_post): ?>
    
          <?php if (!is_null($image = YapbImage::getInstanceFromDb($photoblog_post->ID))): ?>
    
              <div class="menyelement"><a href="<?php echo get_category_link();?>"><img src="<?php echo $image->getThumbnailHref($thumbConfig) ?>" width="<?php echo $image->getThumbnailWidth($thumbConfig) ?>" height="<?php echo $image->getThumbnailHeight($thumbConfig) ?>"/></a><br /><span class="menycat"><?php the_category(); ?></span></div>
    
          <?php endif ?>
    
        <?php endforeach ?>
    
    <?php endwhile; endif; ?>

    But as you can see here: https://fhoto.se/nytest/?page_id=300 I don’t get the right category info. Any ideas? Any help will be much appreciated! Thanks!

    Fred

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter fhoto

    (@fhoto)

    ok, I’m almost there.. I managed to get the category link working, but I can’t find a way to display the category title.. any clues?

    this is the loop I’m using now (scroll far right for the category title code):

    <?php if (have_posts()): while (have_posts()): the_post(); ?>
    
    <?php 
    
      $photoblog_posts = get_posts('tag=frontar&numberposts=20' );
    
      $thumbConfig = array(
        'w=260',
        'q=100',
        'fltr[]=usm|80|0.2|0'
      );
    
    ?>
    
        <?php foreach($photoblog_posts as $photoblog_post): ?>
    
          <?php if (!is_null($image = YapbImage::getInstanceFromDb($photoblog_post->ID))): ?>
    
    <? $mypost = $photoblog_post->ID ?>
    <?php $terminfo = $wpdb->get_results("SELECT term_id
    FROM $wpdb->term_relationships, $wpdb->term_taxonomy
    WHERE object_ID = $mypost AND $wpdb->term_taxonomy.term_taxonomy_ID = $wpdb->term_relationships.term_taxonomy_ID
    ORDER BY term_ID"); ?>
    
    <?// get the first term_id and assign it to $cat?>
    <?php $termrecord = $terminfo[0]; ?>
    <?php $cat = $termrecord->term_id; ?>
    
              <div class="menyelement"><a href="<?php echo get_category_link($cat) ?>"><img src="<?php echo $image->getThumbnailHref($thumbConfig) ?>" width="<?php echo $image->getThumbnailWidth($thumbConfig) ?>" height="<?php echo $image->getThumbnailHeight($thumbConfig) ?>"/><div class="menytitel"><?php wp_list_categories('include= . $cat . &style=none' ); ?></div></a></div>
    
          <?php endif ?>
    
        <?php endforeach ?>
    
    <?php endwhile; endif; ?>

    Thread Starter fhoto

    (@fhoto)

    and this is how it shows: https://fhoto.se/nytest/

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can’t get category links for posts! Ideas? (YAPB)’ is closed to new replies.