get_category_link gives wrong URL
-
I’m trying to create a page template that shows blog post underneath the main page. I’m trying to keep it general by getting the page page slug then finding blog posts from a category with a matching slug.
I use get_category_by_slug() to get the category info. then use the term_id from that in get_category_link()
BUT it returns the link for the page instead of the category archive.
../blog/catslug
instead of
../blog/category/catslug
Here’s the code
<?php get_template_part( 'loop', 'page' ); $post_obj = $wp_query->get_queried_object(); $post_name = $post_obj->post_name; query_posts( 'category_name='.$post_name ); $this_cat = get_category_by_slug($post_name); ?> <h1 class="page-title"><a href="<?php esc_url(get_category_link( $this_cat->term_id )); ?>" title="More <?php echo $this_cat->cat_name; ?> posts from the blog archive" rel="bookmark">Recent <?php echo $this_cat->cat_name; ?> posts from the blog</a></h3> <?php get_template_part( 'loop', 'category' ); ?>
I think this is a bug. Anybody got any suggestions?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘get_category_link gives wrong URL’ is closed to new replies.