【问题标题】:Display Post Terms and add link显示帖子条款并添加链接
【发布时间】:2018-06-21 22:37:36
【问题描述】:

我创建了这个简码来在特定帖子(自定义帖子类型)上显示我的术语(自定义分类):

// First we create a function
function list_terms_forme_juridique_taxonomy() {
global $post;
$terms = wp_get_post_terms( $post->ID, 'forme_juridique',array('fields' 
=> 'names') );
ob_start();
if( count( $terms) > 0) {  
echo '<ul>';
echo '<li>' . implode( '</li><li>', $terms) . '</li>';
echo '</ul>';
}
return ob_get_clean();
}

// Add a shortcode that executes our function
add_shortcode( 'forme_juridique', 'list_terms_forme_juridique_taxonomy' 
);

我正在尝试在我的条款中添加一个链接 (url) 以重定向到条款页面,但我还没有成功。

有什么帮助吗?

【问题讨论】:

    标签: wordpress taxonomy custom-taxonomy


    【解决方案1】:

    为此使用get_term_link()function:

    // First we create a function
    function list_terms_forme_juridique_taxonomy() {
    global $post;
    $terms = wp_get_post_terms($post->ID, 'forme_juridique');
    ob_start();
    if( count( $terms) > 0) {
        echo '<ul>';
        foreach($terms as $term){
            $term_link = get_term_link($term, 'forme_juridique');
    
            echo '<li><a href="'. $term_link .'">' . $term->name . '</a></li>';
    
        }
    
    echo '</ul>';
    }
    return ob_get_clean();
    }
    
    // Add a shortcode that executes our function
    add_shortcode( 'forme_juridique', 'list_terms_forme_juridique_taxonomy' 
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-09
      • 1970-01-01
      • 2016-06-20
      • 2019-11-28
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多