WP主题如何支持WooCommerce主题

1、创建woocommerce.php文件

复制2013主题下的page.php到同一位置(主题根目录下),将它重命名为woocommerce.php;

 
2、修改woocommerce.php文件

用上述编辑软件打开woocommerce.php,将:

    <div id=“content” class=“site-content” role=“main”>  
      
                        <!–这里全部删除–>  
      
    </div><!– #content –>  

 

之间的PHP和HTML混合的代码全部删除;然后在删除的 隔膜计量泵位置添加上如下内容:

 

    <?php /* The loop */ ?>   
    <?php if ( have_posts() ) :   
     /*Add the follow function. */  
    woocommerce_content();   
      
    endif; ?>  

 

之后你会看到:

 

    <div id=“content” class=“site-content” role=“main”>   
        <?php /* The loop */ ?>   
        <?php if ( have_posts() ) :   
         /*Add the follow function. */  
        woocommerce_content();   
        endif; ?>   
    </div><!– #content –>  

 

这个文件的修改先这样了;
3.修改functions.php文件

用上述编辑软件打开隔膜计量泵主题根目录下的functions.php,在其末尾处添加:

    ///   
      
    //Add support   
    add_theme_support( ’woocommerce’ );   
      
    // Unhook the WooCommerce wrappers;   
    remove_action( ’woocommerce_before_main_content’, ’woocommerce_output_content_wrapper’, 10);   
    remove_action( ’woocommerce_after_main_content’, ’woocommerce_output_content_wrapper_end’, 10);   
      
    add_action(‘woocommerce_before_main_content’, ’my_theme_wrapper_start’, 10);   
    add_action(‘woocommerce_after_main_content’, ’my_theme_wrapper_end’, 10);   
      
    function my_theme_wrapper_start() {   
      echo ’<section id=“main”>’;   
    }   
      
    function my_theme_wrapper_end() {   
      echo ’</section>’;   
    }  

 
4.测试主题对WooCommerce的支持

下载并安装上WooCommerce插件,然后到Products下发布一个商品,然后到前台看下效果(如果不怕慢,请点击小图看大图):

 

Wordpress主题如何支持WooCommerce

在上图中,我简单粗暴的调整了下页面布局:在主题根目录下用上述编辑软件打开style.css,在末尾处添加:

    /*  
    For WooCommerce support TEST by Suifengtec  
    */  
    .type-product{   
        width:90%;   
        margin:0 5%;   
        padding:16px;   
        padding:1.6rem;   
    }  


如何在Wordpress的feed中显示文章的缩略图/特色图像。

WordPress 在feed中显示缩略图/特色图像

关键词:Wordpress WordPress特色图像

直接上代码:

    function cwp_featured_image_in_rss_feed( $content ) {   
        global $post;    http://www.chenggong.edu.cn/
        if( is_feed() ) {   
            if ( has_post_thumbnail( $post->ID ) ){   
                $output = ’<div style=“display:block; clear:both;”>’.get_the_post_thumbnail( $post->ID, ’medium’, array( ’style’ => ’float:right; margin:0 0 10px 10px;’ ) ).’</div>’;   
                $content = $output . $content;   
            }   
        }   
        return $content;   
    }   
    add_filter(‘the_excerpt_rss’, ’cwp_featured_image_in_rss_feed’);   
    add_filter(‘the_content_feed’, ’cwp_featured_image_in_rss_feed’);  

将上述代码添加至您所用主题根目录下的functions.php,即可在feed中显示缩略图了,但是请自行控制好大小。
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值