Support » Themes and Templates » Article thumbnail-link to category

  • Hello everybody,

    want to ask if it’s possible with wordpress to link an article (article thumbnail) to an category and not to the article? (only on main page)

    This is my page:

    If I have published an article on the main page and click on the thumbnail picture I will come to the articles. But I want to come to the categories (in the black boxes)

    Perhaps someone can help me. Would be great. Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • That’s a cool idea. Its possible with a separate loop. Do you know about the loop, and have you built sites with multiple loops before?

    No I didn’t. Is it difficult? Because I’m a beginner working with wordpress



    Forum Moderator

    no need for a separate loop;

    just locate where those posts are output, possibly in home.php (?), and change the link around the thumbnails to a link to the first category of that post.

    the link to the first post category would be:

    <?php $cats = get_the_category();
    $cat_link = get_category_link( $cats[0]->term_id ); ?>

    if you have problems, please post the full code of home.php of your theme


    try to work on it, but didn’t get it.

    Thats the home.php file:

    <?php get_header(); ?>
    		$i = 0;
    		global $do_not_duplicate;
    		$temp = $wp_query;
    		$wp_query = NULL;
    		$args = array(
    			'paged' => $paged,
    			'post__not_in' => $do_not_duplicate
    		$wp_query = new WP_Query();
    		while ($wp_query->have_posts()) : $wp_query->the_post(); $i++; ?>
    		<div class="span-8 post-<?php the_ID(); ?><?php if ($i == 3) { ?> last<?php  } ?>">
    			<h6 class="archive-header"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title() ?></a></h6>
    			<?php get_the_image( array( 'custom_key' => array( 'thumbnail' ), 'default_size' => 'thumbnail', 'width' => '310', 'height' => '150' ) ); ?>
    			<?php the_excerpt(); ?>
    			<?php $cats = get_the_category(); $cat_link = get_category_link( $cats[0]->term_id ); ?>
    		<?php if ($i == 3) { ?><div class="archive-stack clear"></div><?php $i = 0; } ?>
    		<?php endwhile; ?>
    		<div class="clear"></div>
    		<div class="navigation clearfix">
    			<div><?php next_posts_link('&laquo; Older Entries') ?></div>
    			<div><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    		</div><div class="clear"></div>
    		<?php $wp_query = NULL; $wp_query = $temp;?>
    <?php get_template_part( 'bottom' ); ?>
    <?php get_footer(); ?>

    Think thats the line I have to work with??:

    <?php $cats = get_the_category(); $cat_link = get_category_link( $cats[0]->term_id ); ?>

    But how exactly?

    Thank you for help

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Article thumbnail-link to category’ is closed to new replies.