How to get the dynamic category link in custom query from specific category

To get my requirement I used below code...

<div class="home_single_item_headline">
     <?php query_posts('post_type=post&category_name=Browser&post_status=publish&posts_per_page=6&paged='. get_query_var('paged')); ?>
     <a href="<?php bloginfo('url'); ?>/category/<?php $category = get_the_category(); echo $category[0]->category_nicename; ?>">Browser</a>                        
</div>
<div class="home_single_item_column floatleft">    
    <?php get_template_part('post-loop')?>
</div>

but I get the category link randomly means other category link. What will be the proper solution?

Upvotes: 0

Views: 828

Answers (1)

Ovidiu Iacomi
Ovidiu Iacomi

Reputation: 776

You should use get_category_link($category_id).

So in your case you would have:

<?php $category = get_the_category(); ?>
<a href="<?php echo get_category_link($category[0]->term_id); ?>">Browser</a>

Upvotes: 1

Related Questions