WordPress.org

Forums

next/pre navigation problem in single-gallery.php (4 posts)

  1. Garavani
    Member
    Posted 11 months ago #

    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
    clicked on mini galleries below:
    http://www.stefanseifert.com/IM_photo/?gallery=sabine-frank

  2. WP Sites - Brad Dalton
    Member
    Posted 11 months ago #

    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

  3. Garavani
    Member
    Posted 11 months ago #

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

  4. Garavani
    Member
    Posted 11 months ago #

    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

Reply

You must log in to post.

About this Topic