我创建了一个简短的代码,生成一些自定义的帖子列表并作为html元素返回 . 这是一个示例代码:
function shortcode(){
$return_string = '';
// query
query_posts(array('post_type' => 'custom_post', 'orderby' => 'menu_order', 'order' => 'ASC', 'showposts' => -1));
if (have_posts()) :
while (have_posts()) : the_post();
$return_string .= '<p>Hello</p>';
endwhile;
endif;
wp_reset_query();
return $return_string;
}
add_shortcode('shortcode', 'shortcode');
然后使用WooCommerce钩子和短代码一起显示商店页面上每个产品的产品列表 . 但它打破了商店专栏,并以单列显示所有产品 . 这是动作钩子的代码:
function add_on_loop() {
echo do_shortcode('[shortcode]');
}
add_action( 'woocommerce_after_shop_loop_item', 'add_on_loop', 30);
我尝试删除循环,然后它没有任何问题 . 非常感激您的帮忙 .