Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #702550

    Hi guys

    My clients wanted << Previous Next >> text links above each single post and each single portfolio

    AND

    Wanted the << >> links to always show and just disable the one that can;t go anywhere rather than hide it 9eg when you reach the first item in a category)

    AND

    Only shuffle between post/portfolio items in the same post category or portfolio category

    I have it working for posts by adding a function found on here

    add_filter('avia_post_nav_settings', 'avia_post_nav_settings_mod');
    function avia_post_nav_settings_mod($settings)
    {
            $settings['is_fullwidth']  = false;
            $settings['same_category'] = true;
            return $settings;
    }

    and in the single.php im using checks to see if a previous or next post existng and if not output just dumb >> Next text with no link

    That works nicely for news posts but weirdly having issues trying to get the same working with portfolio categories. Next >> works fine but the previous just doesnt work

    Please can you tell me the easiest way to get your avia post nav to never hide but just outpout and style differently for posts and portfolio single items please :)

    Tight deadline launch monday :)

    <div class="container single-post-nav-container" >
    <div class="navigation">   <p>      <a href="/news/">< Back to news home </a></p>
       <div>
       <?php
    		//display link to previous and next portfolio entry
    		echo avia_post_nav();//https://codex.wordpress.org/Next_and_Previous_Links
       ?><?php 
       
       if ( get_previous_post(true) ) {
    		previous_post_link('', '', true); 
    	} else {
    		echo '<div class="disabled-post-nav">';
    		echo '<a class="avia-post-nav avia-post-prev with-image" ><span class="entry-info-wrap"><span class="entry-info"><span class="entry-image"></span></span></a>';
    		echo '</div>';
    	}
    	
        if ( get_next_post(true) ) {
    		next_post_link('', '', true); 
    	} else {
    		echo '<div class="disabled-post-nav">';
    		echo '<a class="avia-post-nav avia-post-next with-image" ><span class="entry-info-wrap"><span class="entry-info"><span class="entry-image"></span></span></a>';
    		echo '</div>';
    	} ?>
       </div></div></div>
    • This topic was modified 8 years ago by wrongjon.
    #703020

    Solved :)

    by copying the function to my child theme and adding an extra check to see if a post exists and if not putput dummy << >> links that dont click

    I also had to add the taxonomy name in the single-portfolio.php and to tell it to keep in same category only

    echo avia_post_nav(true,'case-studies');

    if(!function_exists('avia_post_nav'))
    {
    	function avia_post_nav($same_category = false, $taxonomy = 'category')
    	{
    		global $wp_version;
    	        $settings = array();
    	        $settings['same_category'] = $same_category;
    	        $settings['excluded_terms'] = '';
    			$settings['wpversion'] = $wp_version;
            
    		//dont display if a fullscreen slider is available since they overlap 
    		if((class_exists('avia_sc_layerslider') && !empty(avia_sc_layerslider::$slide_count)) || 
    			class_exists('avia_sc_slider_full') && !empty(avia_sc_slider_full::$slide_count) ) $settings['is_fullwidth'] = true;
    
    		$settings['type'] = get_post_type();
    		//if ($taxonomy) {
    			//$settings['taxonomy'] = $taxonomy;
    		//} else {
    			$settings['taxonomy'] = ($settings['type'] == 'portfolio') ? 'portfolio_entries' : $taxonomy;
    		//}
    
    		if(!is_singular() || is_post_type_hierarchical($settings['type'])) $settings['is_hierarchical'] = true;
    		if($settings['type'] === 'topic' || $settings['type'] === 'reply') $settings['is_bbpress'] = true;
    
    	        $settings = apply_filters('avia_post_nav_settings', $settings);
    	        if(!empty($settings['is_bbpress']) || !empty($settings['is_hierarchical']) || !empty($settings['is_fullwidth'])) return;
    	
    	        if(version_compare($settings['wpversion'], '3.8', '>=' ))
    	        {
    	            $entries['prev'] = get_previous_post($settings['same_category'], $settings['excluded_terms'], $settings['taxonomy']);
    	            $entries['next'] = get_next_post($settings['same_category'], $settings['excluded_terms'], $settings['taxonomy']);
    	        }
    	        else
    	        {
    	            $entries['prev'] = get_previous_post($settings['same_category']);
    	            $entries['next'] = get_next_post($settings['same_category']);
    	        }
    	        
    		$entries = apply_filters('avia_post_nav_entries', $entries, $settings);
            $output = "";
    
    		foreach ($entries as $key => $entry)
    		{
                if(empty($entry)) { // continue;
    			
    			//echo '<div class="disabled-post-nav">';
    		//echo '<a class="avia-post-nav avia-post-next with-image" ><span class="entry-info-wrap"><span class="entry-info"><span class="entry-image"></span></span></a>';
    		//echo '</div>';
    			
    			$output .= "<div class='disabled-post-nav'><a class='avia-post-nav avia-post-{$key} {$class}' >";
    		    //$output .= "    <span class='label iconfont' ".av_icon_string($key)."></span>";
    		    $output .= "    <span class='entry-info-wrap'>";
    		    $output .= "        <span class='entry-info'><span class='entry-image'></span>";
    		   // $tc1     = "            <span class='entry-title'>{$the_title}</span>";
    if($image)  //$tc2     = "            <span class='entry-image'>{$image}</span>";
                //$output .= $key == 'prev' ?  $tc1.$tc2 : $tc2.$tc1;
                $output .= "        </span>";
                //$output .= "    </span>";
    		    $output .= "</a></div>";
    			
    			} else {
    			$the_title 	= isset($entry->av_custom_title) ? $entry->av_custom_title : avia_backend_truncate(get_the_title($entry->ID),75," ");
    			$link 		= isset($entry->av_custom_link)  ? $entry->av_custom_link  : get_permalink($entry->ID);
    			$image 		= isset($entry->av_custom_image) ? $entry->av_custom_image : get_the_post_thumbnail($entry->ID, 'thumbnail');
    			
                $tc1   = $tc2 = "";
                $class = $image ? "with-image" : "without-image";
    
                $output .= "<a class='avia-post-nav avia-post-{$key} {$class}' href='{$link}' >";//.$same_category.$taxonomy;
    		    $output .= "    <span class='label iconfont' ".av_icon_string($key)."></span>";
    		    $output .= "    <span class='entry-info-wrap'>";
    		    $output .= "        <span class='entry-info'>";
    		    $tc1     = "            <span class='entry-title'>{$the_title}</span>";
    if($image)  $tc2     = "            <span class='entry-image'>{$image}</span>";
                $output .= $key == 'prev' ?  $tc1.$tc2 : $tc2.$tc1;
                $output .= "        </span>";
                $output .= "    </span>";
    		    $output .= "</a>";
    			} //end if JJA
    		}
    		return $output;
    	}
    }
    #703026

    Hi!

    Glad you figured it out and thank you for sharing your solution! Let us know if you have any other questions or issues :)

    Cheers!
    Yigit

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Post nav links always show but disabled when at first or last rather than hide’ is closed to new replies.