Skip Navigation

[Resolved] create next link, link child previous post type

This support ticket is created 8 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by pabloS-3 8 years ago.

Assigned support staff: Luo Yang.

Author
Posts
#287580
image1.JPG
image2.JPG

I am trying to:

create navigation link post for the category of 'Categoria Obra' (Custom Post Type Child) , now I get in chronological order, (image1)

I visited this URL:

hidden link
hidden link
hidden link

I expected to see:

image 2

Instead, I got:

#287767

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

It is not possible within Views, since the problem next/previous links is setup by your theme file, for example in wordpress default theme twentyfifteen, file single.php, line 31~39:

// Previous/next post navigation.
			the_post_navigation( array(
				'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'twentyfifteen' ) . '</span> ' .
					'<span class="screen-reader-text">' . __( 'Next post:', 'twentyfifteen' ) . '</span> ' .
					'<span class="post-title">%title</span>',
				'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'twentyfifteen' ) . '</span> ' .
					'<span class="screen-reader-text">' . __( 'Previous post:', 'twentyfifteen' ) . '</span> ' .
					'<span class="post-title">%title</span>',
			) );

It is using wordpress function the_post_navigation to display the next/previous links. Views can not modify the result from it.

But you can try create custom function/shortcode to replace it, for example, the parent post type is using slug "artist", you can try add below codes in your theme/functions.php:

add_shortcode('wpv-child-prev', 'wpv_child_prev');
add_shortcode('wpv-child-next', 'wpv_child_next');
function wpv_child_prev() {
    return wpv_child(-1, 'PREV');
}
function wpv_child_next() { 
    return wpv_child(1, 'NEXT'); 
}
function wpv_child($step, $label) {
    global $post;
    $artist = get_post_meta($post->ID, '_wpcf_belongs_artist_id', true);
    $works = get_posts(array('post_type' => 'works', 'meta_key' => '_wpcf_belongs_artist_id', 'meta_value' => $artist, 'numberposts' => -1));
    foreach ($works as $i => $work) {
        if ($work->ID == $post->ID) break;
    }
    $i += $step;
    if (isset($works[$i])) return '<a href="' . get_permalink($works[$i]) . '">' . $label . '</a>';
}

Then you can use [wpv-child-prev] and [wpv-child-next] shortcode in the child post content to display the next/previous links. and I suggest you create a content template for your child posts.

More help:
Designing WordPress Content with Content Templates
https://toolset.com/documentation/user-guides/view-templates/

#287773

thank you very much !, I spent a lot of hours with this and with your help I solved it in five minutes. Really Appreciate your help.