默认情况下,WordPress按字母顺序(而不是按在标记框中输入的顺序)排序自定义分类法(在本例中为标记)。
有人知道如何按照自定义分类法在编辑后屏幕中输入的顺序显示它们吗?
所讨论的url是:http://granadatheater.com/
GGW(Goes Good With)艺术家目前按字母顺序排列,他们希望更改它,以便按照输入的相同方式排列。
因此,如果输入它的Artist1、Artist3、Artist2,那么它应该显示在网站的前端。
默认情况下,WordPress按字母顺序(而不是按在标记框中输入的顺序)排序自定义分类法(在本例中为标记)。
有人知道如何按照自定义分类法在编辑后屏幕中输入的顺序显示它们吗?
所讨论的url是:http://granadatheater.com/
GGW(Goes Good With)艺术家目前按字母顺序排列,他们希望更改它,以便按照输入的相同方式排列。
因此,如果输入它的Artist1、Artist3、Artist2,那么它应该显示在网站的前端。
这不可能“开箱即用”。。。
默认的“orderby”选项为(升序或降序)
ID名称默认值在法典中有详细说明。
--
也就是说,有一些聪明的女士;这里的先生们。如果有人能解决这个问题,我相信其中一个人能!
经过相当多的搜索和广泛的测试,我找到了答案。
将此代码添加到主题的函数中。php:
function set_the_terms_in_order ( $terms, $id, $taxonomy ) {
$terms = wp_cache_get( $id, "{$taxonomy}_relationships_sorted" );
if ( false === $terms ) {
$terms = wp_get_object_terms( $id, $taxonomy, array( \'orderby\' => \'term_order\' ) );
wp_cache_add($id, $terms, $taxonomy . \'_relationships_sorted\');
}
return $terms;
}
add_filter( \'get_the_terms\', \'set_the_terms_in_order\' , 10, 4 );
function do_the_terms_in_order () {
global $wp_taxonomies; //fixed missing semicolon
// the following relates to tags, but you can add more lines like this for any taxonomy
$wp_taxonomies[\'post_tag\']->sort = true;
$wp_taxonomies[\'post_tag\']->args = array( \'orderby\' => \'term_order\' );
}
add_action( \'init\', \'do_the_terms_in_order\');
(信贷:这基于但改进了-http://wordpress.kdari.net/2011/07/listing-tags-in-custom-order.html)我知道这是一种欺骗,但你可以用Simple Custom Post Order 插件。它是免费的,并且允许您对文章类型之外的分类法进行排序。
我一直在努力寻找自定义分类法中按字母顺序排列的子术语的答案。。。我不建议更改核心WP文件,所以下面是我添加到分类中的内容。php文件列出自定义分类描述,并按字母顺序链接到子术语。修改以满足您的需要,我希望这对其他人有所帮助。
// Get Main Taxonomy for use in template file
$term = get_term_by( \'slug\', get_query_var( \'term\' ), get_query_var( \'taxonomy\' ) );
$termTaxonomy = $term->taxonomy;
<h1><?php echo apply_filters( \'the_title\', $term->name ); ?></h1>
<?php // test for description before unleashing a div
if ( !empty( $term->description ) ):
echo \'<div class="description">\';
echo $term->description;
echo \'</div>;
endif; ?>
// Now get children terms, using get_term & \'child_of\' get\'s us alphabetical order
$termchildren = get_terms( $termTaxonomy, array(
\'child_of\' => $term->term_id,
\'hierarchical\' => 0,
\'fields\' => \'ids\',
\'hide_empty\' => 0
) );
// Make an alphabetical linked list
echo \'<ul>\';
foreach ($termchildren as $child) {
$term = get_term_by( \'id\', $child, $termTaxonomy );
// Modify this echo to customize the output for each child term
echo \'<li><a href="\' . get_term_link( $term->name, $termTaxonomy ) . \'" alt="\' .$term->description. \'">\' . $term->name . \'</a></li>\';
}
echo \'</ul>\';
在网页中显示好的顺序之后,可能是:
将“orderby”=>“term\\u group”放入wp\\u get\\u post\\u术语中
例子:
“poste”是我的自定义分类名称,请输入您的
$poste = wp_get_post_terms($post->ID, \'poste\', array("fields" => "names", "orderby" => "term_group"));
if(!empty($poste[0])){ echo $poste[0];}
if(!empty($poste[1])){
echo " - ", $poste[1]; }
我有一个有趣的问题,希望有人能尽快回答。我已经创建了自己的metabox,它基于“我的metabox代码”(下面的列表)正确地显示了我创建的“event\\u types”分类中所有术语的下拉列表。我遇到的问题是,当从下拉列表中选择不同的术语并更新帖子时,能够保存/更新与帖子相关的术语。在对各种代码位进行修补之后,我发现通过手动将term\\u ID number[用逗号分隔]输入数组区域,我得到了我想要的结果。例如,如果在保存帖子时,函数将调用此代码wp_set_post_terms( $post_id