• Resolved Reiniepress

    (@reiniepress)


    First of, thanks for this theme

    I would like to navigation through the same parent category. Thus where could I set the next_post and prev_post to true (using a my child theme)

    Thanks

Viewing 10 replies - 1 through 10 (of 10 total)
  • Hi @reiniepress,

    Could you clarify your end goal for me? I’m not certain on what it is you’re trying to achieve.

    If you could provide me with a link to your site and specific examples of pages that you’re trying to change, that’d be a great help.

    Thanks!

    Thread Starter Reiniepress

    (@reiniepress)

    sure, I have two types of posts, videos and blog. When I open a video post I would like that the previous or next post be a video and not a blog entry if it is the next or previous one.
    To limit navigation, i need to set the option in the code, (i checked the codex) but not sure where is is.

    you can see an exemple here

    the next post in not a video (navigation at the bottom) , but i would like to limit it to videos.

    thanks

    Thread Starter Reiniepress

    (@reiniepress)

    Thanks so much for clarifying, @jasperh.

    Gazette’s references to next_posts_link() and previous_posts_link() can be found within a function in the theme’s inc/template-tags.php file.

    You can make edits to this function by first setting up a child theme.

    In case you haven’t already set a child theme up, the following guides will help out:

    After you have completed that step, copy the the_posts_navigation() from inc/template-tags.php file to your child theme’s functions.php file:

    function the_posts_navigation() {
    	// Don't print empty markup if there's only one page.
    	if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
    		return;
    	}
    	?>
    	<nav class="navigation posts-navigation" role="navigation">
    		<h2 class="screen-reader-text"><?php _e( 'Posts navigation', 'gazette' ); ?></h2>
    		<div class="nav-links">
    
    			<?php if ( get_next_posts_link() ) : ?>
    			<div class="nav-previous"><?php next_posts_link( __( 'Older posts', 'gazette' ) ); ?></div>
    			<?php endif; ?>
    
    			<?php if ( get_previous_posts_link() ) : ?>
    			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts', 'gazette' ) ); ?></div>
    			<?php endif; ?>
    
    		</div><!-- .nav-links -->
    	</nav><!-- .navigation -->
    	<?php
    }

    You can edit directly from there.

    Hope that helps out!

    Thread Starter Reiniepress

    (@reiniepress)

    It says it is already declared in wp-includes/link-template.php from wordpress itself (and there is no if exist statement there…)
    Also when i look at the gazette file it says
    @todo Remove this function when WordPress 4.3 is released. I am on 4.6.1.

    Thread Starter Reiniepress

    (@reiniepress)

    When I remove the if exists statement from the gazette template i.e if ( ! function_exists( ‘the_post_navigation’ ) ) : then it says the same so I guess it is ignored?..

    Hi @reiniepress,

    It says it is already declared in wp-includes/link-template.php from wordpress itself (and there is no if exist statement there…)

    Where specifically are you seeing that message?

    The function should be added to your child theme’s functions.php file without any if statement surrounding it.

    The if statement should only surround the function in the parent theme’s inc/template-tags.php file.

    As the child theme’s files load before the parent’s, the fact that the_posts_navigation() exists in the child theme will be picked up and the if statement will stop the parent theme’s version of the function from running.

    The if statement is what makes for a “pluggable function” that can be overridden via a child theme. You can read a little more information on these types of functions here, if you’re interested:

    https://code.tutsplus.com/tutorials/a-guide-to-overriding-parent-theme-functions-in-your-child-theme–cms-22623

    @todo Remove this function when WordPress 4.3 is released. I am on 4.6.1.

    Thanks for spotting that! I’ll report it back to the theme’s author.

    Thread Starter Reiniepress

    (@reiniepress)

    Yes I did all that. It seems the function is in the core of wordpress,
    and it is ignored in template-tag.php because of the conditional statement.
    To investigate further, I removed the conditional statement from that file and
    removing the function from my child theme. I ended up with the same error message.
    That basically it already exists in the core of wordpress. So maybe, and that could
    well be wrong but maybe it was added since v4.3… (which would explain the @to do lines).
    Or I am uterly useless..

    Thus maybe the navigation options have to be changed in another function.. ?

    Hi @reiniepress,

    You’re totally right and apologies for my oversight here!

    Upon further investigation I found that the_post_navigation() was introduced to core in 4.1:

    https://developer.www.ads-software.com/reference/functions/the_post_navigation/

    You can edit that function by copying the parent’s single.php to your child theme and locating the following code:

    <?php
    	// Previous/next post navigation.
    	the_post_navigation( array(
    		'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'gazette' ) . '</span> ' . '<span class="screen-reader-text">' . __( 'Next post:', 'gazette' ) . '</span> ' . '<span class="post-title">%title</span>',
    		'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'gazette' ) . '</span> ' . '<span class="screen-reader-text">' . __( 'Previous post:', 'gazette' ) . '</span> ' . '<span class="post-title">%title</span>',
    	) );
    ?>

    You can add the ‘in_same_term’ => true, argument to the above code to achieve what you’re after.

    Let me know if that works out.

    Thread Starter Reiniepress

    (@reiniepress)

    yes it was a matter of finding the right place. thks

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘navigation same category’ is closed to new replies.