Support » Fixing WordPress » next/pre navigation problem in single-gallery.php

  • 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:

    $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

    parent Gallery page:
    clicked on mini galleries below:

Viewing 3 replies - 1 through 3 (of 3 total)
  • Try just using the value like this:

    $prevPost = get_previous_post(false, 287);
    $nextPost = get_next_post(false, 287);


    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:

                                    $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">
                                                if ($prevPost != '') {
                                                    previous_post_link('<i class="icon-prev"></i> %link');
                                                echo '
                                                if ($nextPost != '') {
                                                    next_post_link('%link <i class="icon-next"></i>');
                                <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'); ?>

    [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.]

    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘next/pre navigation problem in single-gallery.php’ is closed to new replies.