dongshi8359
2018-05-28 11:06
浏览 27
已采纳

将图像页面横幅添加到商店页面

I am using WordPress 4.9.6.

I have set the shop page to be the home-page.

How do I add a page banner to the shop page. I would like to add it just above the breadcrumb trail.

I have tried adding this to the following page archive-product.php

if (is_shop()) {
        $args = array('taxonomy' => 'product_cat');
        $product_categories = get_categories( $args  );
        $term_id = $product_categories[0]->term_id;  
        $content = get_term_meta($term_id, 'cat_meta');
        if(isset($content[0]['cat_header'])){
            echo do_shortcode($content[0]['cat_header']);
        }
}

Unfortunately, not able to add any image to the page.

图片转代码服务由CSDN问答提供 功能建议

我正在使用WordPress 4.9.6。

我已经设置了商店 页面是主页。

如何将页面横幅添加到商店页面。 我想将它添加到痕迹路径上方。

我尝试将其添加到以下页面archive-product.php

  if(is_shop()){
 $ args = array('taxonomy'=>'product_cat'); 
 $ product_categories = get_categories($ args); 
 $ term_id = $ product_categories [0]  - >  term_id;  
 $ content = get_term_meta($ term_id,'cat_meta'); 
 if(isset($ content [0] ['cat_header'])){
 echo do_shortcode($ content [0] ['cat_header'])  ; 
} 
} 
   
 
 

不幸的是,无法向页面添加任何图像。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • drmeu26880 2018-05-29 06:07
    已采纳

    You can achieve using 2 methods.

    1) Add your static image directly at the beginning of archive-product.php echo "<img src='{YOUR_IMAGE_PATH}'>";

    2) Add filter in your theme's functions.php file.

     add_action ('woocommerce_archive_description' , 'shop_banner',99);
     function shop_banner() {
       echo  '<img src="{YOUR_IMAGE_PATH}" >';
      }
    
    已采纳该答案
    打赏 评论
  • donglizuo8892 2018-05-28 22:06

    I'm not so sure if I understand exactly what you want. But this is what I understand so far.

    If you want to display an Static image banner above the breadcrumbs in your Shop Page. You could use the woocommerce_before_main_content action.

    function BannerShop(){
    
      if(is_shop()){
        echo '<img src="https://localhost/demosite/wp-content/uploads/2015/06/512x356.png" >';
      }
    }
    add_action( 'woocommerce_before_main_content', 'BannerShop', 10 );
    

    Here i show the before and after. BTW I don't know what theme are you using so it may be displayed different.

    Before https://i.stack.imgur.com/Mv2YK.jpg

    After https://i.stack.imgur.com/nTfCa.jpg

    打赏 评论