Customize url from the_terms

时间:2016-12-12 作者:shipwreck

我使用了自定义帖子类型、自定义分类法和Beatiful Taxonomy Filters 在以下位置创建瑜伽姿势的可排序档案:dev.stretcheveryday.yoga/poses.

尝试更进一步,从单个姿势链接到姿势分类档案。例如:;“”One Legged Bridge “是中度仰卧后弯”显示为

<h3><?php the_title(); ?> is a <?php the_terms( $post->ID, \'level\' ); ?> <?php the_terms( $post->ID, \'position\' ); ?> <?php the_terms( $post->ID, \'focus\' ); ?></h3>
几乎可以使用,但这些术语需要/摆姿势/添加到URL中,以便链接到适当的存档。

我怎样才能预先准备好/poses/ 到\\u terms URL?

谢谢你的时间。

1 个回复
SO网友:shipwreck

比我想象的还要复杂。可能不漂亮但是it works.

功能。php

function get_btf_link( $taxonomy = \'\', $post = false ){
if ( ! $post ) {
    global $post;
}
$url = get_post_type_archive_link( $post->post_type );
$terms = get_the_terms( $post, $taxonomy);
if ( $terms ) {
    foreach ( $terms as $term ) {
        $url = $taxonomy;
        break;
    }
}
return $url;
}
单体式。php

<?php the_title(); ?> is a
<a href="<?php echo home_url() ?>/poses/<?php echo get_btf_link(\'level\') ?>/<?php $terms = wp_get_object_terms( $post->ID, \'level\', array(\'fields\'=>\'slugs\',)); echo strip_tags( $terms[0]); ?>">
    <?php echo strip_tags(get_the_term_list($post->ID, \'level\')); ?>
</a>,
<a href="<?php echo home_url() ?>/poses/<?php echo get_btf_link(\'position\') ?>/<?php $terms = wp_get_object_terms( $post->ID, \'position\', array(\'fields\'=>\'slugs\',)); echo strip_tags( $terms[0]); ?>">
    <?php echo strip_tags(get_the_term_list($post->ID, \'position\')); ?>
</a>,
<a href="<?php echo home_url() ?>/poses/<?php echo get_btf_link(\'focus\') ?>/<?php $terms = wp_get_object_terms( $post->ID, \'focus\', array(\'fields\'=>\'slugs\',)); echo strip_tags( $terms[0]); ?>">
    <?php echo strip_tags(get_the_term_list($post->ID, \'focus\')); ?>
</a>

相关推荐