首页 文章

在WooCommerce中的归档产品页面上移动页面 Headers

提问于
浏览
2

在我的WooCommerce商店页面(存档 - 产品模板)上,我正在尝试移动页面 Headers ,使其位于站点内部区域之外,而不是在 Headers 区域中,就像它在我网站上的其他页面上一样 . 我想在它后面添加一个全宽图像,所以我需要它在当前钩子之外 .

我也希望能够在我的 functions.php 文件中进行此编辑,以便我不必担心WooCommerce升级 .

以下是控制 Headers 的归档产品页面上的代码:

get_header( 'shop' ); ?>

<?php
    /**
     * woocommerce_before_main_content hook.
     *
     * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
     * @hooked woocommerce_breadcrumb - 20
     */
    do_action( 'woocommerce_before_main_content' );
?>

    <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>

        <h1 class="page-title"><?php woocommerce_page_title(); ?></h1>

    <?php endif; ?>

    <?php
        /**
         * woocommerce_archive_description hook.
         *
         * @hooked woocommerce_taxonomy_archive_description - 10
         * @hooked woocommerce_product_archive_description - 10
         */
        do_action( 'woocommerce_archive_description' );
    ?>

我可以添加什么来添加到我的functions.php来覆盖页面 Headers 的位置?你可以看到page in question here.

2 回答

  • 1

    首先,可以通过主题覆盖WooCommerce模板(更好地使用子主题),避免了woocommerce更新的问题 .

    要删除WooCommerce存档页面 Headers ,您可以使用以下代码:

    add_filter( 'woocommerce_show_page_title', '__return_false' );
    

    代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中 .


    然后,您将需要编辑header.php主题模板,以使页面 Headers 显示在商店页面上(最佳解决方案是创建子主题并将header.php从父主题复制到子主题) . 您还可以使用WooCommerce条件标记来定位商店页面和其他WooCommerce存档页面...

  • 0
    • wp-content\plugins\woocommerce\templates\archive-product.php 复制到 wp-content\themes\your-theme\woocommerce\archive-product.php

    • 更改代码:

    <?php
    /**
     * The Template for displaying product archives, including the main shop page which is a post type archive
     *
     * This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
     *
     * HOWEVER, on occasion WooCommerce will need to update template files and you
     * (the theme developer) will need to copy the new files to your theme to
     * maintain compatibility. We try to do this as little as possible, but it does
     * happen. When this occurs the version of the template file will be bumped and
     * the readme will list any important changes.
     *
     * @see 	    https://docs.woocommerce.com/document/template-structure/
     * @author 		WooThemes
     * @package 	WooCommerce/Templates
     * @version     3.3.0
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    }
    
    get_header( 'shop' );
    
    /**
     * Hook: woocommerce_before_main_content.
     *
     * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
     * @hooked woocommerce_breadcrumb - 20
     * @hooked WC_Structured_Data::generate_website_data() - 30
     */
    
    ?>
        <header class="woocommerce-products-header">
            <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
                <h1 class="woocommerce-products-header__title page-title"><?php woocommerce_page_title(); ?></h1>
            <?php endif; ?>
    
            <?php
            /**
             * Hook: woocommerce_archive_description.
             *
             * @hooked woocommerce_taxonomy_archive_description - 10
             * @hooked woocommerce_product_archive_description - 10
             */
            do_action( 'woocommerce_archive_description' );
            ?>
        </header>
    <?php
    
    do_action( 'woocommerce_before_main_content' );
    
    if ( have_posts() ) {
    
    	/**
    	 * Hook: woocommerce_before_shop_loop.
    	 *
    	 * @hooked wc_print_notices - 10
    	 * @hooked woocommerce_result_count - 20
    	 * @hooked woocommerce_catalog_ordering - 30
    	 */
    	do_action( 'woocommerce_before_shop_loop' );
    
    	woocommerce_product_loop_start();
    
    	if ( wc_get_loop_prop( 'total' ) ) {
    		while ( have_posts() ) {
    			the_post();
    
    			/**
    			 * Hook: woocommerce_shop_loop.
    			 *
    			 * @hooked WC_Structured_Data::generate_product_data() - 10
    			 */
    			do_action( 'woocommerce_shop_loop' );
    
    			wc_get_template_part( 'content', 'product' );
    		}
    	}
    
    	woocommerce_product_loop_end();
    
    	/**
    	 * Hook: woocommerce_after_shop_loop.
    	 *
    	 * @hooked woocommerce_pagination - 10
    	 */
    	do_action( 'woocommerce_after_shop_loop' );
    } else {
    	/**
    	 * Hook: woocommerce_no_products_found.
    	 *
    	 * @hooked wc_no_products_found - 10
    	 */
    	do_action( 'woocommerce_no_products_found' );
    }
    
    /**
     * Hook: woocommerce_after_main_content.
     *
     * @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
     */
    do_action( 'woocommerce_after_main_content' );
    
    /**
     * Hook: woocommerce_sidebar.
     *
     * @hooked woocommerce_get_sidebar - 10
     */
    do_action( 'woocommerce_sidebar' );
    
    get_footer( 'shop' );
    

相关问题