[英]To display category,sub-category,sub-sub categories and postname in url permalink in wordpress php
[英]Wordpress - Permalink of sub-category in loop
我有一個模板循環瀏覽您選擇的主要類別中的每個子類別。 我想要超鏈接的每個標題,因此,如果您選擇一個子類別,現在可以轉到該特定類別的帖子。
但是,當使用<?php get_category_link( $category_id ); ?>
<?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>
更改
<h2><a href="#"><?php single_cat_title(); ?></a></h2>
至
<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.