kirkslater
Member
Posted 2 years ago #
Hopefully this will be an easy one to sort out for you all.
On the loop on the homepage I am just displaying the thumbs from the latest 4 posts. Instead of having a permalink to its post, I want it to take the user to the category its posted into.
A strange request, I know, but any ideas?
Many thanks
if you could post the code which shows the thumbnail (plus a few lines before and after), this might be a starting point to help.
a general code to get the link to the first category of a post (in the loop)
<?php $category = get_the_category();
$cat_link = get_category_link( $category[0]->cat_ID ); ?>
assuming that your code uses the_permalink() to link the thumb; replacing it with echo $cat_link; might work.
kirkslater
Member
Posted 2 years ago #
Hi thanks for the help, the code is below. I've tried something similar to whats you've said, but it didn't seem to work.
<div id="latestframe">
<?php if (have_posts()) : ?>
<?php query_posts('posts_per_page=4'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="latestboxes"><a href="<?php $category = get_the_category(); echo $category[0]->cat_slug; ?>"><img src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" border="0" /></a></div>
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<p>Sorry, no results where found.</p>
<?php endif; ?>
</div>
Let me know what you think ;)
<div class="latestboxes"><a href="<?php $category = get_the_category(); echo $category[0]->cat_slug; ?>"><img...
as you know, cat_slug is just the 'clean' version of the category name (lowercase letters, no special characters, joined with - ) and is not a link or path to the category archive page.
you could try as suggested:
<div class="latestboxes"><a href="<?php $category = get_the_category(); echo get_category_link( $category[0]->cat_ID ); ?>"><img...
make a backup copy of your theme file before editing