简体   繁体   English

WordPress-循环中子类别的永久链接

[英]Wordpress - Permalink of sub-category in loop

I've got a template looping through each of the sub-categories in the main category you've selected. 我有一个模板循环浏览您选择的主要类别中的每个子类别。 The title of each I would like hyperlinked, so if you select a sub-category you can now go to that specific categories posts. 我想要超链接的每个标题,因此,如果您选择一个子类别,现在可以转到该特定类别的帖子。

However when using <?php get_category_link( $category_id ); ?> 但是,当使用<?php get_category_link( $category_id ); ?> <?php get_category_link( $category_id ); ?> , it outputs the permalink of the parent category instead. <?php get_category_link( $category_id ); ?> ,它改为输出父类别的永久链接。

<div class="row">
<?php $i = 1; $categories = get_categories("child_of=$cat"); foreach ($categories as $cat) { ?>
    <div class="col-md-6">
        <?php query_posts("cat=$cat->cat_ID&posts_per_page=1&order=ASC&orderby=name"); ?>
        <div class="top-category-container">
            <div class="category-label">
                <span>Latest From</span>
                <h2><a href="#"><?php single_cat_title(); ?></a></h2>
            </div>
            <?php while (have_posts()) : the_post(); ?>
                <div class="post">
                    <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
                    <div class="article-img">
                        <a href="<?php the_permalink(); ?>"><?php echo the_post_thumbnail('', array('class' => 'img-responsive')); ?></a>
                    </div>
                    <p><?php the_excerpt(); ?></p>
                </div>
            <?php endwhile; ?>
        </div>
    </div>
<?php } ?> 
</div>

LIVE URL: http://dev.madd-cow.com/category/man-rehab/ 实时网址: http//dev.madd-cow.com/category/man-rehab/

Change 更改

<h2><a href="#"><?php single_cat_title(); ?></a></h2>

to

<h2><a href="<?php $cat = get_term_by('name', single_cat_title('',false), 'category'); echo $cat->slug; ?>"><?php single_cat_title(); ?></a></h2>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM