admin管理员组文章数量:1122846
I have seen this issue in quite a few threads so apologies if I've replicated an issue here but I've had no joy in attempting to implement the solutions I have found.
I have a custom post type: show
, to which is assigned a custom taxonomy: show_status
. This can be set either to current
or past
.
In the single-show.php
template of my theme I have placed the following:
<div class="newerlink"><p><?php next_post_link('%link', 'Next ›', $in_same_term = true, $excluded_terms = '', $taxonomy = 'show_status' ); ?></p></div>
<div class="olderlink"><p><?php previous_post_link('%link', '‹ Previous', $in_same_term = true, $excluded_terms = '', $taxonomy = 'show_status' ); ?></p></div>
I want the user to be able to navigate within shows categorised as current
OR as past
but not to move from one type to the other.
I have tried several versions of these links and all show either no links at all or links which do not differentiate between the show_status
and pass from post to post without stopping. All have been variants on the basic:
<div class="newerlink"><p><?php next_post_link('%link', 'Next ›', TRUE ); ?></p></div>
<div class="olderlink"><p><?php previous_post_link('%link', '‹ Previous', TRUE ); ?></p></div>
I imagine I haven't quite got it right yet. I've also tried this method, which rendered links but didn't respect the change in show_status
either.
The loop in single-show.php
is as standard in a post template:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
// content
<?php endwhile; ?>
<?php else: ?>
<?php endif; ?>
Where different content is needed by category I am using:
<?php if (has_term('current', 'show_status')) { ;?>
or
<?php if (has_term('past', 'show_status')) { ;?>
to differentiate.
How can I get this to work as intended?
I have seen this issue in quite a few threads so apologies if I've replicated an issue here but I've had no joy in attempting to implement the solutions I have found.
I have a custom post type: show
, to which is assigned a custom taxonomy: show_status
. This can be set either to current
or past
.
In the single-show.php
template of my theme I have placed the following:
<div class="newerlink"><p><?php next_post_link('%link', 'Next ›', $in_same_term = true, $excluded_terms = '', $taxonomy = 'show_status' ); ?></p></div>
<div class="olderlink"><p><?php previous_post_link('%link', '‹ Previous', $in_same_term = true, $excluded_terms = '', $taxonomy = 'show_status' ); ?></p></div>
I want the user to be able to navigate within shows categorised as current
OR as past
but not to move from one type to the other.
I have tried several versions of these links and all show either no links at all or links which do not differentiate between the show_status
and pass from post to post without stopping. All have been variants on the basic:
<div class="newerlink"><p><?php next_post_link('%link', 'Next ›', TRUE ); ?></p></div>
<div class="olderlink"><p><?php previous_post_link('%link', '‹ Previous', TRUE ); ?></p></div>
I imagine I haven't quite got it right yet. I've also tried this method, which rendered links but didn't respect the change in show_status
either.
The loop in single-show.php
is as standard in a post template:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
// content
<?php endwhile; ?>
<?php else: ?>
<?php endif; ?>
Where different content is needed by category I am using:
<?php if (has_term('current', 'show_status')) { ;?>
or
<?php if (has_term('past', 'show_status')) { ;?>
to differentiate.
How can I get this to work as intended?
Share Improve this question edited Jul 26, 2017 at 16:46 mtm asked Jul 26, 2017 at 11:35 mtmmtm 438 bronze badges 11 | Show 6 more comments1 Answer
Reset to default 0I managed to solve this, with some steering in the right direction in the comments under my question, by specifying different templates for different taxonomy terms using single-show.php
to divert as follows:
if ( have_posts() ) { the_post(); rewind_posts(); }
if (has_term('current', 'show_status')) {
include(TEMPLATEPATH . '/single-show-current.php');
}
elseif (has_term('past', 'show_status')) {
include(TEMPLATEPATH . '/single-show-past.php');
}
else {
include(TEMPLATEPATH . '/single-default.php');
}
Then, in the single-show-current.php
and single-show-past.php
templates I specified navigation based on term rather than taxonomy, as pointed out by Max, above (thank you for the help getting here).
The solution is based on this code at Bucket Press.
$postlist_args = array(
'posts_per_page' => -1,
'orderby' => 'menu_order title',
'order' => 'ASC',
'post_type' => 'show',
'show_status' => 'current'
);
$postlist = get_posts( $postlist_args );
$ids = array();
foreach ($postlist as $thepost) {
$ids[] = $thepost->ID;
}
$thisindex = array_search($post->ID, $ids);
$previd = $ids[$thisindex-1];
$nextid = $ids[$thisindex+1];
if ( !empty($previd) ) {
echo '<div class="olderlink"><p><a rel="prev" href="' . get_permalink($previd). '">‹ Previous</a></p></div>';
}
if ( !empty($nextid) ) {
echo '<div class="newerlink"><p><a rel="next" href="' . get_permalink($nextid). '">Next ›</a></p></div>';
}
Finally, to make this user-proof I installed the radio buttons for taxonomies plugin and applied it to this post type, effectively reducing the number of possible assignations to 1.
本文标签: PreviousNext custom post links within custom taxonomy
版权声明:本文标题:PreviousNext custom post links within custom taxonomy 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736288744a1928159.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
endwhile
command. – mtm Commented Jul 26, 2017 at 14:56_
. – Max Yudin Commented Jul 26, 2017 at 15:10show_status
and adjusted all templates accordingly but am seeing the same problem with the above links (obviously altered to match). – mtm Commented Jul 26, 2017 at 15:43<?php next_post_link('%link', 'Next ›', TRUE ); ?>
– mtm Commented Jul 26, 2017 at 15:45