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中顯示縮略圖了,但是請自行控制好大小。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章