- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hi,
I have a simple loop in wordpress, let’s say something like that:
<?php query_posts(‘category_name=paint&showposts=-1&order=DESC’);?>
<?php while (have_posts()) : the_post();?>
<?php endwhile; ?>
Now I don’t want it to go to the permalink of the post, because I want to display all the posts in subcategory, so is there a way instead to link it to the post permalink i would like to link it to the category permalink?
Oh, I Got it
<?php
$the_cat = get_the_category();
$category_name = $the_cat[0]->cat_name;
$category_link = get_category_link( $the_cat[0]->cat_ID ); ?>
<a>" title="<?php echo $category_name ?>"><?php echo $category_name ?></a>
But how do i show on the archive.php only the posts from that category?
If you go to http://www.yoursite.com/category/paint, then it will show all the posts of the “paint” category, using the standard archive.php file.
However, if you create a new template called archive-paint.php, then it will take that template. Every other URL/category (e.g. http://www.yoursite.com/category/something) will then just use archive.php.
So you can just put your custom code in archive-paint.php and that will then only be used for the “paint” category.