wordpress - Woocommerce - 产品单页中的作者简介
问题描述
我正在为书籍类别的产品单页创建自定义主题。我正在为 wordpress 使用 themerex bookshleft 主题和为每本书添加作者标签的插件附加标签(themerex 也是)。但我想在单本书页面中显示作者传记,而不仅仅是出现在元信息之间的 woocommerce 单品摘要中的作者链接。我尝试在 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 行的附加标签文件中创建了这个钩子 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);
?>
只需在单个产品页面中使用执行操作并在 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')
)
);
}
}
推荐阅读
- elasticsearch - 如何将数据从 Cassandra 加载到 ELK
- oracle-apex-5.1 - Oracle Apex 5.1 交互式网格逐行更改列类型
- swift - IBOutlet 无 - 按钮
- selenium - 如何在 TestNg 和 Allure 报告框架中添加超时测试用例失败?
- android - 如何使用片段中的按钮更改 View Pager 中的片段?
- c++ - 在 Visual C++ 中解析 XML 的问题
- drupal-modules - 有哪些易于构建的 Drupal 模块来设计工作门户和社区站点?
- java - How to make a String replacement program without any for loop in java?
- react-native - React native - 如何以编程方式更改标题栏图标?
- user-interface - 如何将 2D UI 图像拖放到 3D 游戏对象上,然后在我们放置 2D UI 图像的位置实例化 3D 游戏对象?