我尝试了一些方法来删除<br>
在短代码之间创建时,我在另一个线程中发现了一个,看起来很有希望,但没有成功:
function the_content_filter($content) {
$block = join("|",array("category_product_list", "category_products"));
$rep = preg_replace("/(<p>)?\\[($block)(\\s[^\\]]+)?\\](<\\/p>|<br \\/>)?/","[$2$3]",$content);
$rep = preg_replace("/(<p>)?\\[\\/($block)](<\\/p>|<br \\/>)?/","[/$2]",$rep);
return $rep;
}
add_filter("the_content", "the_content_filter");
我读到wpautop可以做到这一点,但对我来说什么都不管用。我是否需要以某种方式修改我的实际短代码?下面是我正在使用的一个短代码:
function category_product_list( $atts ) {
extract(shortcode_atts(array(
\'category\' => \'\',
\'per_page\' => -1,
\'orderby\' => \'title\',
\'order\' => \'asc\'
), $atts));
$meta_query = WC()->query->get_meta_query();
$tax_query = WC()->query->get_tax_query();
$tax_query[] = array(
\'taxonomy\' => \'product_cat\',
\'field\' => \'slug\',
\'terms\' => array( esc_attr($category) ),
\'operator\' => \'IN\',
);
$args = array(
\'post_type\' => \'product\',
\'post_status\' => \'publish\',
\'ignore_sticky_posts\' => 1,
\'posts_per_page\' => $per_page,
\'orderby\' => $orderby,
\'order\' => $order,
\'meta_query\' => $meta_query,
\'tax_query\' => $tax_query
);
$products = new WP_Query( $args );
if ( $products->have_posts() ) :
$term_list = wp_get_post_terms($products->post->ID, \'product_cat\', array("fields" => "all"));
$first_term = $term_list[0];
$first_term_name = $first_term->name;
$url = get_permalink();
$id = $products->post->ID;
// $html_out = \'<h2>Courses</h2>\';
$html_out = \'<ul class="simple-sitemap-courses">\';
$html_out .= \'<li class="page-item page-item-\' . $id . \'"><a href="\' . $url . \'">\' . $first_term_name . \'</a>\';
$html_out .= \'<ul class="children">\';
while ($products->have_posts()) :
$products->the_post();
$product = get_product( $products->post->ID );
$course_title = get_the_title();
$url = get_permalink();
$id = $products->post->ID;
// Output product information here
$html_out .= \'<li class="page-item page-item-\' . $id . \'"><a href="\' . $url . \'">\' . $course_title . \'</a></li>\';
endwhile;
$html_out .= \'</ul>\';
$html_out .= \'</li>\';
$html_out .= \'</ul>\';
else : // No results
$html_out = "No Courses Found.";
endif;
wp_reset_postdata();
return $html_out;
}
add_shortcode( \'category_product_list\', \'category_product_list\' );