此代码用于在页面上显示产品属性。
如何按slug对其进行排序/排序?它们当前按名称排序。
global $post;
$terms = get_the_terms( $post->ID, \'pa_size\');
foreach ( $terms as $term ) {
echo "<li>" .$term->name. "</li>";
}
此代码用于在页面上显示产品属性。
如何按slug对其进行排序/排序?它们当前按名称排序。
global $post;
$terms = get_the_terms( $post->ID, \'pa_size\');
foreach ( $terms as $term ) {
echo "<li>" .$term->name. "</li>";
}
您需要自己对其进行排序:
$terms = get_the_terms( $post->ID, \'category\');
foreach ( $terms as $term ) {
$newterms[$term->slug] = $term;
}
ksort($newterms);
foreach ( $newterms as $term ) {
echo "<li>" .$term->name. "</li>";
}
或者,如果你喜欢冒险,也可以使用过滤器:function alpha_sort_terms($terms) {
remove_filter(\'get_the_terms\',\'alpha_sort_terms\');
foreach ( $terms as $term ) {
$newterms[$term->slug] = $term;
}
ksort($newterms);
return $newterms;
}
add_filter(\'get_the_terms\',\'alpha_sort_terms\');
$terms = get_the_terms( $post->ID, \'category\');
foreach ( $terms as $term ) {
echo "<li>" .$term->name. "</li>";
}
我的目标是一个单页垂直滚动的网站。我使用此代码逐个显示所有页面: <!-- All Pages --> <?php $pages = get_pages(); foreach ($pages as $page_data) { $content = apply_filters(\'the_content\', $page_