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



我正在为书籍类别的产品单页创建自定义主题。我正在使用 themerex bookshleft 主题进行 wordpress 和插件附加标签(themerex 也是(,为每本书添加作者标签。但我想在单本书页面中展示作者传记,而不仅仅是出现在 woocommerce 单一产品摘要中元信息之间的作者链接。 我尝试将此钩子插入内容单产品书籍.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 行的附加标签文件中创建了此钩子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')
)
);
}
}

但我不知道如何在单本书页面的自定义模板中使用它。我感谢任何帮助!

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

只需在单个产品页面中使用执行操作 并在功能add_action钩子中触发您的功能代码.php或在您的插件中。 然后此代码将在 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')
)
);
}
}

最新更新