Woocommerce作為WordPress旗下功能非常強大的一款電子商務插件,現如今,因其簡單易用且功能強大的屬性為眾多外貿企業所青睞,但畢竟核心研發團隊是歪果仁,外文才是主要闡述語言,國內開發環境及開發文檔缺少,導致中文文檔較外文文檔尤為缺乏。當然,外語專業的人士閱讀障礙並不大。那麼我們想實現一些方便使用Woocommerce的功能怎麼辦呢?譬如,在一個獨立頁面生成所有商品分類方便顧客進入特定分類…
我們想要添加一個商品分類頁面就必須對Woocommerce的代碼風格及編寫規範有一定了解,因此僅適合具備一定編程基礎的人進行二次開發或者直接使用現成的代碼,接下來我將公布自己經過測試並成功實現商品分類頁面的方法希望幫到有需要的人!
將下方代碼添加進functions.php外加一個php文件即可實現:
if ( ! function_exists( 'storefront_product_categories' ) ) { function storefront_product_categories( $args ) {
if ( is_woocommerce_activated() ) {
$args = apply_filters( 'storefront_product_categories_args', array( 'limit' => 30, 'columns' => 3, 'child_categories' => 0, 'orderby' => 'name', ) );
echo '<section aria-label="Product Categories">';
do_action( 'storefront_homepage_before_product_categories' );
echo '<h2>' . wp_kses_post( $args['title'] ) . '</h2>';
do_action( 'storefront_homepage_after_product_categories_title' );
echo storefront_do_shortcode( 'product_categories', array( 'number' => intval( $args['limit'] ), 'columns' => intval( $args['columns'] ), 'orderby' => esc_attr( $args['orderby'] ), 'parent' => esc_attr( $args['child_categories'] ), ) );
do_action( 'storefront_homepage_after_product_categories' );
echo '</section>'; } }}
<?php
get_header(); ?>
<div id="primary" class="content-area"> <main id="main" class="site-main" role="main">
<?php remove_action( 'homepage','storefront_homepage_content' ,10); remove_action( 'homepage','storefront_recent_products' ,30); remove_action( 'homepage','storefront_featured_products' ,40); remove_action( 'homepage','storefront_popular_products' ,50); remove_action( 'homepage','storefront_on_sale_products',60 ); remove_action( 'homepage','storefront_best_selling_products' ,70); do_action( 'homepage' ); ?>
</main> </div> <?php get_sidebar(); ?><?php get_footer(); >——組織名片——
WordPressX | 加入組織 · 業務合作 Rovun 首席會長
致力於集結大中華區WordPress愛好者!
合作微信:OwnMalls
WordPress組織出品,點擊「閱讀原文」
↓↓↓