Skip Navigation

[Resolved] Either adding prev/next to content template or moving related posts to theme

This support ticket is created 7 years, 2 months 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 11 replies, has 2 voices.

Last updated by emilyT 7 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#564793
4-NP-web-gallery-series-painting-2017.jpg

Tell us what you are trying to do?
I'm trying to create a page which shows the following in this order:
1. Current item details (child of parent post)
2. Prev/Next navigation
3. Related items (children of the same parent)
I've attached an image of what I'm trying to achieve.

Is there any documentation that you are following?
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

I'm part way there - but as the prev/next navigation is part of the theme single-painting.php template it's appearing below the related items, rather than above.

What is the link to your site?
hidden link

Is there any way to either:
a. Move the prev/next links into the content template rather than the theme file so that I can position them?
or
b. Add a content template or view into the theme file so that it can be below the navigation links.

Many thanks for your help!
Emily

#564807

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Emily,

Thank you for contacting our support forum.

I should be able to help you achieve part A and what would be needed is to convert the pagination code into shortcodes.

Could you let me know the pagination code that your theme uses?

Thanks,
Shane

#565175

Hi Shane, that's great thanks for offering to help.

At the moment I've got the following in my single-painting.php theme file:

<div class="navigation">
  <div class="previousnav"><?php next_post_link('< %link'); ?></div>
  <div class="currentexb">PAINTINGS IN THIS SERIES</div>
  <div class="nextnav"><?php prev_post_link('%link >'); ?></div>
</div> <!-- end navigation -->

If you're also able to point me in the direction of how to get the prev/next links to work through alphabetically by title that would be amazing.

Many thanks, Emily

#565237

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Emily,

Please try adding this to your functions.php file.

// Add Shortcode
function pagination() {

	$pagination = "<div class='navigation'><div class='previousnav'>".next_post_link('< %link')."</div>
	  <div class='currentexb'>PAINTINGS IN THIS SERIES</div>
	  <div class='nextnav'>".prev_post_link('%link >')."</div>
	</div>";
	
	return $pagination ;

}
add_shortcode( 'pagination', 'pagination' );

Then try using the shortcode by doing this [pagination]

Please let me know if this helps.
Thanks,
Shane

#565263
frontend.png
content-template.png
functions.png

Hi Shane

I'm afraid I haven't been able to get that to work. I've attached screenshots of the content template, functions and the frontend so that you can see what I've done and the result it's had (a mostly blank screen).

Have I missed something?

Cheers, Emily

#565321

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Emily,

Would you mind providing me with admin access to this so that I can investigate the issue further?

Thanks,
Shane

#565586

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Emily,

Thank you however i'm not sure whats happening here because i see that this is the correct content template.
hidden link

However any changes I made to the content template is not reflected on the frontend.

Maybe im missing something.
Thanks,
Shane

#565594

Hi Shane

That's because the pagination shortcode basically breaks the page. I've removed [pagination] from the content template and you can see that the painting page now loads. Here's an example:
hidden link

If you add [pagination] back in it will break again.

That's the current issue I think!
Cheers, Emily

#565619

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Emily,

I've got it to work but due to some limitations its not 100% exactly like your screenshot but it still works.

Please let me know if this helps.
Thanks,
Shane

#565803

Hi Shane

Thanks, that looks brilliant. I've got a couple of refinements I'd like to make, is this something you can help me with?
1. I'd like the next/prev to cycle through the paintings alphabetically by title rather than chronologically. I've added letters (A, B, C etc) to the painting titles so that we can see that working.
2. If there's no 'next post' is it possible for that to either not display or not be a link? At the moment if I go to the first in the sequence (hidden link) the next post link just reloads the page we're already on, which is a bit confusing.

Best wishes, Emily

#565934

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Emily,

I've refined the code a bit for you so it gets the title and removes the link if there are no next or previous posts.

	// Add Pagination Shortcode
	function pagination() {
		$next_post = get_next_post();
		$previous_post = get_previous_post();
		$prev_pagination= '';
		$next_pagination = '';

		if($previous_post != 0 ){
			
			$prev_pagination = "<div class='navigation'><div class='previousnav'> <a href='".get_permalink($previous_post->ID)."'> << ".get_the_title($previous_post->ID)."</a></div>";
		}
		if($next_post != 0){
			$next_pagination = "<div class='nextnav'><a href='".get_permalink($next_post->ID)."'> ".get_the_title($next_post->ID).">></a></div>";
		}

    $pagination = "<div class='currentexb'><a href='<em><u>hidden link</u></em>''>GALLERY</a> >".get_the_title()."</div>";
	

    return $prev_pagination.$pagination.$next_pagination;
 
	}
	add_shortcode( 'pagination', 'pagination' );

Additionally its not possible to paginate based on the title of the posts and its getting the post based on the date of publish.

Please let me know if this helps.
Thanks,
Shane

#566424

Thanks Shane, I really appreciate your help. I'm marking this resolved - I'll have to find another way around the order of the item nav.

Thanks again, Emily