我想显示某个类别中产品的下拉菜单。
<select>
<option value="CODE HERE">Volvo</option>
</select>
所以根据Wordpress编码..
<?php
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
好的,所以我进一步调查,我希望根据以下内容制作一个单页模板https://developer.wordpress.org https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/我正在为 Storefront 使用一个名为 NOVA WP 的子主题。
为了制作这个“单页模板”,我复制了 page.php 并将其重命名为page-buildit.php
This is Mypage http://www.ofixcomp.com/buildit/我实际上在其中编辑代码。我确实复制了代码,但结果是空白的
发现了这个:WooCommerce:创建短代码来显示产品类别 http://www.remicorson.com/woocommerce-create-a-shortcode-to-display-product-categories/但我的理解是我们不能再用新的 WordPress 版本来做到这一点了。
<?php
$args = array(
'order' => 'ASC',
'hide_empty' => $hide_empty,
'include' => $ids,
'posts_per_page' =>'-1'
);
$product_categories = get_terms( 'product_cat', $args );
echo "<select>";
foreach( $product_categories as $category ){
echo "<option value = '" . esc_attr( $category->slug ) . "'>" . esc_html( $category->name ) . "</option>";
}
echo "</select>";
?>
看一下这个。这是获取产品类别的方法!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)