Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>These functions allow you to set the depth you want to use to determine the next page. So in the question, the user was on '3-series', so the depth would be 2. So, the link returned would be to the "Audi" page. </p> <p>It's used like this in your template (my example is using an image for the link text):</p> <pre><code>$nextIMG = '&lt;img src="'.get_template_directory_uri().'/images/icon-nav-right.png"/&gt;'; echo next_project_link($nextIMG); </code></pre> <p>And place this in functions.php:</p> <pre><code> /* * Next Project Link */ function next_project_link($html) { global $post; // Change this to set what depth you want the next page of $parent_depth = 2; $ancestors = get_post_ancestors($post); $current_project_id = $ancestors[$parent_depth-1]; // Check for cached $pages $pages = get_transient( 'all_pages' ); if ( empty( $transient ) ){ $args = array( 'post_type' =&gt; 'page', 'order' =&gt; 'ASC', 'orderby' =&gt; 'menu_order', 'post_parent' =&gt; $ancestors[$parent_depth], 'fields' =&gt; 'ids', 'posts_per_page' =&gt; -1 ); $pages = get_posts($args); set_transient('all_pages', $pages, 10 ); } $current_key = array_search($current_project_id, $pages); $next_page_id = $pages[$current_key+1]; if( isset($next_page_id) ) { // Next page exists return '&lt;a class="next-project" href="'.get_permalink($next_page_id).'"&gt;'.$html.'&lt;/a&gt;'; } } /* * Previous Project Link */ function previous_project_link($html) { global $post; // Change this to set what depth you want the next page of $parent_depth = 2; $ancestors = get_post_ancestors($post); $current_project_id = $ancestors[$parent_depth-1]; // Check for cached $pages $pages = get_transient( 'all_pages' ); if ( empty( $transient ) ){ $args = array( 'post_type' =&gt; 'page', 'order' =&gt; 'ASC', 'orderby' =&gt; 'menu_order', 'post_parent' =&gt; $ancestors[$parent_depth], 'fields' =&gt; 'ids', 'posts_per_page' =&gt; -1 ); $pages = get_posts($args); set_transient('all_pages', $pages, 10 ); } $current_key = array_search($current_project_id, $pages); $prev_page_id = $pages[$current_key-1]; if( isset($prev_page_id) ) { // Previous page exists return '&lt;a class="previous-project" href="'.get_permalink($prev_page_id).'"&gt;'.$html.'&lt;/a&gt;'; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload