Filter “Last Post / Next Post” navigation bottom of blog posts

Home Forums Forstron Filter “Last Post / Next Post” navigation bottom of blog posts

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #22416
    CorpComm
    Participant

    Filter “Last Post / Next Post” navigation bottom of blog posts

    Resolved

    Hey there! Have you noticed this support service is provided FREE of charge?
    If you like the speed and accuracy of resolutions, please consider supporting me with a small donation. Thank you

    Consider a donation →

    Hello,

    We use Forstron for our company intranet and we have multiple departments that use the Posts feature. We create the posts with the proper categories and then filter through Beaver Builder, so the correct posts show up on the correct departments page.

    When you click into a post, you get the “Next Post/ Last Post” options at the bottom but these are only filtered by publish date. So an IT post could have links to a Human Resources post at the bottom. Is there any way to fix/modify this?

    #22420
    Oliver Juhas
    Keymaster

    Hi CorpComm,

    Probably the easiest solution right now would be to redefine the pluggable function that takes care of this functionality in your child theme‘s functions.php file like this:

    function wm_post_nav() {
    	//Requirements check
    		if ( ! is_singular() || is_page() ) {
    			return;
    		}
    
    	//Helper variables
    		$output = $prev_class = $next_class = '';
    
    		$previous = ( is_attachment() ) ? ( get_post( get_post()->post_parent ) ) : ( get_adjacent_post( false, '', true ) );
    		$next     = get_adjacent_post( false, '', false );
    
    	//Requirements check
    		if (
    				( ! $next && ! $previous )
    				|| ( is_attachment() && 'attachment' == $previous->post_type )
    			) {
    			return;
    		}
    
    		$links_count = absint( (bool) $next ) + absint( (bool) $previous );
    
    	//Preparing output
    		if ( $previous && has_post_thumbnail( $previous->ID ) ) {
    			$prev_class = " has-post-thumbnail";
    		}
    		if ( $next && has_post_thumbnail( $next->ID ) ) {
    			$next_class = " has-post-thumbnail";
    		}
    
    		if ( is_attachment() ) {
    			$output .= get_previous_post_link(
    				'<div class="nav-previous nav-link' . $prev_class . '">%link</div>',
    				__( '<span class="meta-nav">Published In</span> <span class="post-title">%title</span>', 'forstron' )
    			);
    		} else {
    			$output .= get_previous_post_link(
    				'<div class="nav-previous nav-link' . $prev_class . '">%link</div>',
    				__( '<span class="meta-nav">Previous</span> <span class="post-title">%title</span>', 'forstron' ),
    				true
    			);
    			$output .= get_next_post_link(
    				'<div class="nav-next nav-link' . $next_class . '">%link</div>',
    				__( '<span class="meta-nav">Next</span> <span class="post-title">%title</span>', 'forstron' ),
    					true
    			);
    		}
    
    		if ( $output ) {
    			$output = '<nav class="navigation post-navigation links-count-' . $links_count . '"><h1 class="screen-reader-text">' . __( 'Post navigation', 'forstron' ) . '</h1><div class="nav-links">' . $output . '</div></nav>';
    		}
    
    	//Output
    		echo apply_filters( 'wmhook_wm_post_nav_output', $output );
    }

    Best regards,

    Oliver Juhas
    WebMan Design

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.