我正在为图书类别的产品单页创建自定义主题。我使用了用于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')
)
);
}
}
但我不知道如何在单页图书的自定义模板中使用它。我感谢任何帮助!
答案 0 :(得分:0)
<div class="col2-responsive" style="float:left;">
<h3>O autor</h3>
<?php
do_action('woocommerce_author', 'themerex_book_author', 10);
?>
只需在单个产品页面中使用“执行操作” 并在fuctions.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')
)
);
}
}