我正在使用插件Woocommerce进行网上购物。
例如,我有许多类别shoes
, clothes
等等如何显示特定类别的产品?
我在sample page, 但我只想在我的index.php
.
您需要为此创建一个新循环。以下是我用于在主页上显示特定类别产品的代码:
<ul class="products">
<?php
$args = array( \'post_type\' => \'product\', \'posts_per_page\' => 1, \'product_cat\' => \'shoes\', \'orderby\' => \'rand\' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<h2>Shoes</h2>
<li class="product">
<a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
<?php woocommerce_show_product_sale_flash( $post, $product ); ?>
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, \'shop_catalog\'); else echo \'<img src="\'.woocommerce_placeholder_img_src().\'" alt="Placeholder" width="300px" height="300px" />\'; ?>
<h3><?php the_title(); ?></h3>
<span class="price"><?php echo $product->get_price_html(); ?></span>
</a>
<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
</li>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</ul><!--/.products-->
Try this
<?php
echo $product->get_categories(
\', \',
\'<span class="posted_in">\' . _n( \'Category:\', \'Categories:\',
sizeof( get_the_terms( $post->ID, \'product_cat\' ) ),
\'woocommerce\' ) . \' \',
\'.</span>\'
);
?>
还有另一种方法:
您可以将“Shop”页面指定为默认主页。现在,所有产品都将显示在主页上。我是说index.php
.
我正在构建一个插件,它可以对博客页面的评论部分进行大量修改。它认为我不能用一种适用于所有主题的方式来实现这一点——根据使用的特定主题,必须调整一些CSS。我猜在将来,插件还会在数据库中存储一些数据。所以我想它应该是一个插件,而不是一个主题。(?)因此,这些问题:有没有可能以某种方式表明插件只能处理这个主题和那个主题?然后发布一些相当简单的插件版本,每个版本都针对一组特定的主题进行了调整?或者插件应该与。。。是否存在所有主题?除了按主题插件和/或分叉和修改现有主题之外,你能想出其他解决方案吗?也许是儿童主题