0

我正在寻找一种在我的自定义帖子类型的分类中动态输出我的类别描述的方法,但我在 php 中不知如何实现它。我已经彻底阅读了 category_description 上的法典,但没有任何运气。此外,我还从粉碎 mag中查看了本指南。真的希望一些php向导可以让我理顺

在多个前端显示的自定义分类类别上,它应该看起来像这样

<a href="#" title="category_description"></a>

但它看起来像这样

<a href="#" original-title></a>

我正在做的是这个

<?php echo '<li><a href="#" title="'.$presenter->description.'"</a></li>'; ?>

我像这样声明 $presenter 变量

$presenter = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'portfolio' ) );

$presenter 变量基于我的自定义 post_type,它是这样声明的

register_post_type('portfolio', array( 'label' => 'Portfolio Items','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => false,'rewrite' => array('slug' => '%portfolio_page%','with_front'=>true),'query_var' => true,'supports' => array('title','editor','trackbacks','revisions','thumbnail'),'labels' => array (
                'name' => 'Portfolio Items',
                'singular_name' => 'Portfolio Item',
                'menu_name' => 'Portfolio Items',
                'add_new' => 'Add Portfolio Item',
                'add_new_item' => 'Add New Portfolio Item',
                'edit' => 'Edit',
                'edit_item' => 'Edit Portfolio Item',
                'new_item' => 'New Portfolio Item',
                'view' => 'View Portfolio Item',
                'view_item' => 'View Portfolio Item',
                'search_items' => 'Search Portfolio Items',
                'not_found' => 'No Portfolio Items Found',
                'not_found_in_trash' => 'No Portfolio Items Found in Trash',
                'parent' => 'Parent Portfolio Item',
            ),) );

我的自定义分类是这样声明的

function add_custom_taxonomies() {
    register_taxonomy('p_category', 'portfolio', array(
            'hierarchical' => true, 
            'labels' => array( 
                'name' => _x( 'Portfolio Category', 'taxonomy general name', 'theme_x' ), 
                'singular_name' => _x( 'Category', 'taxonomy singular name', 'theme_x' ), 
                'search_items' => __( 'Search Category', 'theme_x' ), 
                'all_items' => __( 'All Categories', 'theme_x' ),
                'parent_item' => __( 'Parent Category', 'theme_x' ), 
                'parent_item_colon' => __( 'Parent Category:', 'theme_x' ), 
                'edit_item' => __( 'Edit Category', 'theme_x' ), 
                'update_item' => __( 'Update Category', 'theme_x' ),
                'add_new_item' => __( 'Add New Category', 'theme_x' ),
                'new_item_name' => __( 'New Category Name', 'theme_x' ), 
                'menu_name' => __( 'Portfolio Categories', 'theme_x' ), 
            ),
            'rewrite' => array( 
                'slug' => 'portfolio-category', 
                'with_front' => false, 
                'hierarchical' => true 
            ), 
        )
    );

};
4

1 回答 1

0

以防万一这有帮助。

你真的不需要详细说明。只需回显函数 category_description(),它会显示自定义分类术语的描述。只需确保在 yourwpurl.com/wp-admin/edit-tags.php?taxonomy=custom-taxonomy-slug 为您的自定义分类术语添加了描述

于 2014-01-31T07:46:41.983 回答