【发布时间】:2016-11-11 00:26:52
【问题描述】:
** 更新(有一点障碍)...
我通过呼应分类术语使代码正常工作。有一个小障碍。您不能选择超过一个术语。否则它不知道该怎么做。这是代码。
为回声做好准备:
<?php $my_terms = get_the_terms( $post->ID, 'YOUR_TERM_HERE' );
if( $my_terms && !is_wp_error( $my_terms ) ) {
foreach( $my_terms as $term ) {}
} ;?>
设置您的页面导航:
<?php // get_posts in same custom taxonomy
$postlist_args = array(
'posts_per_page' => -1,
'orderby' => '',
'order' => 'ASC',
'post_type' => 'YOUR_POST_TYPE_HERE',
'YOUR_TERM_HERE' => array( $term->slug ) // here is your echo
);
$postlist = get_posts( $postlist_args );
// get ids of posts retrieved from get_posts
$ids = array();
foreach ($postlist as $thepost) {
$ids[] = $thepost->ID;
}
// get and echo previous and next post in the same taxonomy
$thisindex = array_search($post->ID, $ids);
$previd = $ids[$thisindex-1];
$nextid = $ids[$thisindex+1];
if ( !empty($nextid) ) {
echo '<a rel="next" href="' . get_permalink($nextid). '"><i class="fa fa-chevron-circle-left" aria-hidden="true"></i></a>';
}
if ( !empty($previd) ) {
echo '<a rel="prev" href="' . get_permalink($previd). '"><i class="fa fa-chevron-circle-right" aria-hidden="true"></i></a>';
} ;?>
如果有人知道如何使用多个分类术语来做到这一点。我真的很想知道。
嗯,这可能很难描述,但我会尽力而为。
我有一个自定义帖子类型about us,并在该 CPT 中创建了一个分层自定义分类法our team。我在该自定义分类中添加了几个项目。
- 团队成员 1
- 团队成员 2
- 等
我想要做的是,当您单击团队成员 1 时,将有一个字段 (div) 显示团队成员 2 的名称并且是可点击的,因此您可以转到下一个团队成员,或返回.. .等等。
这种方式会做一些事情,但它不会通过 post_type 的自定义分类:
<?php // get_posts in same custom taxonomy
$postlist_args = array(
'posts_per_page' => -1,
'orderby' => 'menu_order title',
'order' => 'ASC',
'post_type' => 'over-ons',
'taxonomy' => 'ons_team'
);
$postlist = get_posts( $postlist_args );
// get ids of posts retrieved from get_posts
$ids = array();
foreach ($postlist as $thepost) {
$ids[] = $thepost->ID;
}
// get and echo previous and next post in the same taxonomy
$thisindex = array_search($post->ID, $ids);
$previd = $ids[$thisindex-1];
$nextid = $ids[$thisindex+1];
if ( !empty($previd) ) {
echo '<a rel="prev" href="' . get_permalink($previd). '">previous</a>';
}
if ( !empty($nextid) ) {
echo '<a rel="next" href="' . get_permalink($nextid). '">next</a>';
} ;?>
原代码说:
// get_posts in same custom taxonomy
$postlist_args = array(
'posts_per_page' => -1,
'orderby' => 'menu_order title',
'order' => 'ASC',
'post_type' => 'your_custom_post_type',
'your_custom_taxonomy' => 'your_custom_taxonomy_term'
);
$postlist = get_posts( $postlist_args );
// get ids of posts retrieved from get_posts
$ids = array();
foreach ($postlist as $thepost) {
$ids[] = $thepost->ID;
}
// get and echo previous and next post in the same taxonomy
$thisindex = array_search($post->ID, $ids);
$previd = $ids[$thisindex-1];
$nextid = $ids[$thisindex+1];
if ( !empty($previd) ) {
echo '<a rel="prev" href="' . get_permalink($previd). '">previous</a>';
}
if ( !empty($nextid) ) {
echo '<a rel="next" href="' . get_permalink($nextid). '">next</a>';
}
我的your_custom_taxonomy_term 是什么?因为我认为我的分类法没有一个?
正常导航不起作用:
<?php posts_nav_link('separator','prelabel','nextlabel'); ?>
有没有人做过类似的东西或者知道从哪里开始......
【问题讨论】:
标签: wordpress navigation custom-taxonomy