【问题标题】:Woocommerce - Author bio in product single pageWoocommerce - 产品单页中的作者简介
【发布时间】:2018-09-25 01:23:41
【问题描述】:

我正在为图书类别的产品单页创建自定义主题。我正在为 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')
                        )
                    );

                }
            }

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

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:
    <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')
                        )
                    );
    
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多