Title: next/pre navigation problem in single-gallery.php
Last modified: August 21, 2016

---

# next/pre navigation problem in single-gallery.php

 *  [Garavani](https://wordpress.org/support/users/garavani/)
 * (@garavani)
 * [12 years ago](https://wordpress.org/support/topic/nextpre-navigation-problem-in-single-galleryphp/)
 * Hi all,
 * I am quite used to JS and CSS but very new at php.
    Doing a website I tried to
   modify the next/previous navigation in the single-gallery.php. I am stuck, yet.
   What I want to achieve is to exclude a specific category from the get_next(previous)
   _post. Seems to be simple but i tried everything with that code:
 * <?php
    $prevPost = get_previous_post( $in_same_term = false, $excluded_terms 
   = ‘intro-gallery’, $taxonomy = ‘gallery-category’ ); $nextPost = get_next_post(
   $in_same_term = false, $excluded_terms = ‘intro-gallery’, $taxonomy = ‘gallery-
   category’ );
 *  $root_first_categ = get_post_categories($post->ID, $only_first_cat = true, $
   taxonomy = ‘gallery-category’, $margin_elem_start = ”, $margin_elem_end = ‘ ‘,
   $delimiter = ‘, ‘, $a_class = ‘icon-root’, $show_cat_name = false);
    ?> but couldn’t
   get it work. On my page I have children pages under „Galerien“ in which I posted
   a gallery that I named „Intro Gallery“ (slug ‘intro-gallery’). That are the ones
   I want to exclude form the navigation. But always then the next and previous 
   navigation item disappear. Tried also: $prevPost = get_previous_post($in_same_cat
   = false, $excluded_categories = ‘287’); $nextPost = get_next_post($in_same_cat
   = false, $excluded_categories = ‘287’); with names, IDs etc. Nothing. What I 
   am doing wrong??
 * Some one who could please help me out?
 * Thanks a lot
    Garavani
 * Link:
    parent Gallery page: [http://www.stefanseifert.com/IM_photo/?page_id=50](http://www.stefanseifert.com/IM_photo/?page_id=50)
   clicked on mini galleries below: [http://www.stefanseifert.com/IM_photo/?gallery=sabine-frank](http://www.stefanseifert.com/IM_photo/?gallery=sabine-frank)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [WP SITES](https://wordpress.org/support/users/wordpresssites/)
 * (@wordpresssites)
 * [12 years ago](https://wordpress.org/support/topic/nextpre-navigation-problem-in-single-galleryphp/#post-4929392)
 * Try just using the value like this:
 *     ```
       $prevPost = get_previous_post(false, 287);
       $nextPost = get_next_post(false, 287);
       ```
   
 * Source [http://codex.wordpress.org/Function_Reference/get_previous_post](http://codex.wordpress.org/Function_Reference/get_previous_post)
 *  Thread Starter [Garavani](https://wordpress.org/support/users/garavani/)
 * (@garavani)
 * [12 years ago](https://wordpress.org/support/topic/nextpre-navigation-problem-in-single-galleryphp/#post-4929534)
 * Hi Brad,
 * thanks for your answer!
    Anyway sadly I tried this before. And what is so strange
   about it is that I can type in there any number I want, at once the next/previous
   titles (nav) disappear completely. For me there is no logic in this behavior.
   For when the ID typed there would not exist nothing should be excluded = everything
   should be as it was. Maybe it has to do something with the rest of the code here:
 *     ```
       <?php
                                       $prevPost = get_previous_post(false, XXX);
                                       $nextPost = get_next_post(false, XXX);
   
                                       $root_first_categ = get_post_categories($post->ID, $only_first_cat = true, $taxonomy = 'gallery-category', $margin_elem_start = '', $margin_elem_end = ' ', $delimiter = ', ', $a_class = 'icon-root', $show_cat_name = false);
                                   ?>
                                   <div class="post-navigation">
   
       <ul>
       <li>
                                               <?php
                                                   if ($prevPost != '') {
                                                       previous_post_link('<i class="icon-prev"></i> %link');
                                                   }
                                               ?>
                                           </li>
                                           <?php
                                               if(strlen($root_first_categ)){
                                                   echo '
       <li>'.$root_first_categ.'</li>
       ';
                                               }
                                           ?>
   
       <li>
                                               <?php
                                                   if ($nextPost != '') {
                                                       next_post_link('%link <i class="icon-next"></i>');
                                                   }
                                               ?>
                                           </li>
       </ul>
                                   </div>
                                   <div class="clear bottom-separator"></div>
                                   <?php wp_link_pages(array('before' => '<div class="pagenumbers"><p>Pages:','after' => '</p></div>  ', 'next_or_number' => 'number'));  ?>
                                   <?php get_template_part('social-sharing'); ?>
                               </div>
       ```
   
 * _[Moderator Note: Please post code & markup between backticks or use the code
   button. Your posted code may now have been permanently damaged by the forum’s
   parser.]_
 *  Thread Starter [Garavani](https://wordpress.org/support/users/garavani/)
 * (@garavani)
 * [12 years ago](https://wordpress.org/support/topic/nextpre-navigation-problem-in-single-galleryphp/#post-4929545)
 * I also tried:
 * $prevPost = get_adjacent_post( true, ”, true, ‘gallery-category’ );
    $nextPost
   = get_adjacent_post( true, ”, false, ‘gallery-category’ );
 * instead. Nothing.
    It seems so illogical to me. I have definitely defined some
   galleries with gallery-category: Intro Gallery (intro-gallery) and others simply
   as gallery-category: Hochzeit (hochzeit) [marriage f.e.] Then my logic is: if
   you click and see a gallery from the category „Hochzeit“ than the above code 
   must lead to a navigation next/previous where all galleries categorized as intro-
   gallery must be excluded, even more ONLY GALLERIES WITH CATEGORY hochzeit should
   be visible. But they aren’t. Always ALL GALLERIES are navigable. If I exclude
   some one by ID or anything else the whole navigation terms simply disappear completely.
   I am quite disperated for it seems so simple to me, but evidently I do some wrong
   thinking here. Anyone with any advice? So much thanks Garavani

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘next/pre navigation problem in single-gallery.php’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [excluding](https://wordpress.org/support/topic-tag/excluding/)
 * [navigation](https://wordpress.org/support/topic-tag/navigation/)
 * [next](https://wordpress.org/support/topic-tag/next/)
 * [previous](https://wordpress.org/support/topic-tag/previous/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [Garavani](https://wordpress.org/support/users/garavani/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/nextpre-navigation-problem-in-single-galleryphp/#post-4929545)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
