提问者:小点点

Woocommerce-产品中的作者简介单页


我正在为books类别的产品单页创建一个自定义主题。我正在使用wordpress的themerex bookshleft主题和插件addicional标签(也是themerex)为每本书添加作者标签。但我想显示的作者传记在单书页,而不仅仅是在元信息之间的woocommerce单产品摘要中出现的autor链接。我尝试在content-single-product-books.php文件中插入这个钩子,但不起作用:

<div class="col2-responsive" style="float:left;">
    <h3>O autor</h3>
    <?php   
    add_action('woocommerce_author', 'themerex_book_author', 10);
    do_action('woocommerce_author', 'themerex_book_author', 10);

    ?>
</div>

附加标记插件在第53行addicional标记文件中创建了这个钩子themerex_book_author:

    //Hook into the 'init' action
    add_action('init', 'themerex_book_author', 0);

这个钩子的功能是这样的:

if (!function_exists('themerex_book_author')) {
                function themerex_book_author()
                {

                    themerex_require_data('taxonomy', 'authors', array(
                            'post_type' => array('product'),
                            'hierarchical' => true,
                            'labels' => array(
                                'name' => _x('Authors', 'Taxonomy General Name', 'themerex'),
                                'singular_name' => _x('Author', 'Taxonomy Singular Name', 'themerex'),
                                'menu_name' => __('Author', 'themerex'),
                                'all_items' => __('All Authors', 'themerex'),
                                'parent_item' => __('Parent Author', 'themerex'),
                                'parent_item_colon' => __('Parent Author:', 'themerex'),
                                'new_item_name' => __('New Author Name', 'themerex'),
                                'add_new_item' => __('Add New Author', 'themerex'),
                                'edit_item' => __('Edit Author', 'themerex'),
                                'update_item' => __('Update Author', 'themerex'),
                                'separate_items_with_commas' => __('Separate authors with commas', 'themerex'),
                                'search_items' => __('Search authors', 'themerex'),
                                'add_or_remove_items' => __('Add or remove authors', 'themerex'),
                                'choose_from_most_used' => __('Choose from the most used authors', 'themerex'),
                            ),
                            'show_ui' => true,
                            'show_admin_column' => true,
                            'query_var' => true,
                            'rewrite' => array('slug' => 'authors')
                        )
                    );

                }
            }

但我不知道如何使用它在我的自定义模板为单书页。谢谢你的帮助!


共1个答案

匿名用户

<div class="col2-responsive" style="float:left;">
<h3>O autor</h3>
  <?php   
     do_action('woocommerce_author', 'themerex_book_author', 10);
  ?>

只需在单个产品页面中使用do操作,并在functions.php或插件中的add_action钩子中触发函数代码。则此代码将在do操作中自动激发

    add_action('woocommerce_author', 'themerex_book_author', 10);
if (!function_exists('themerex_book_author')) {
            function themerex_book_author()
            {

                themerex_require_data('taxonomy', 'authors', array(
                        'post_type' => array('product'),
                        'hierarchical' => true,
                        'labels' => array(
                            'name' => _x('Authors', 'Taxonomy General Name', 'themerex'),
                            'singular_name' => _x('Author', 'Taxonomy Singular Name', 'themerex'),
                            'menu_name' => __('Author', 'themerex'),
                            'all_items' => __('All Authors', 'themerex'),
                            'parent_item' => __('Parent Author', 'themerex'),
                            'parent_item_colon' => __('Parent Author:', 'themerex'),
                            'new_item_name' => __('New Author Name', 'themerex'),
                            'add_new_item' => __('Add New Author', 'themerex'),
                            'edit_item' => __('Edit Author', 'themerex'),
                            'update_item' => __('Update Author', 'themerex'),
                            'separate_items_with_commas' => __('Separate authors with commas', 'themerex'),
                            'search_items' => __('Search authors', 'themerex'),
                            'add_or_remove_items' => __('Add or remove authors', 'themerex'),
                            'choose_from_most_used' => __('Choose from the most used authors', 'themerex'),
                        ),
                        'show_ui' => true,
                        'show_admin_column' => true,
                        'query_var' => true,
                        'rewrite' => array('slug' => 'authors')
                    )
                );

            }
        }