WordPress.org

Forums

Frontier
[resolved] Link to previous post in the same category (4 posts)

  1. meravjon
    Member
    Posted 9 months ago #

    Hi ron
    You've helped me to change the link button with this:

    function read_post_button_text($text) {
        return the_title();
    }
    add_filter( 'frontier_continue_reading_text', 'read_post_button_text' );
    
    add_filter( 'pre_option_link_manager_enabled', '__return_true' );

    Now I want to remove the previous button so it will appear only in posts in the same category. can it be done?

  2. ronangelo
    Member
    Theme Author

    Posted 9 months ago #

    I don't quite understand what you're asking, maybe you could explain a bit more. What do you mean by "Previous Button"? You mentioned the code above so I assume you're talking about the Read Post button on the Posts Page/Blog Page.

    Or are you talking about the next/previous post buttons under each Single post? If that is what you mean and you want the Next/Previous buttons to link to posts that are of the same category then add this on your child-theme's functions.php:

    function custom_single_post_nav() {
       $prev_post = get_previous_post(true);
       $next_post = get_next_post(true);
       $post_nav_single = '';
    
       if ( !empty($prev_post) )
          $post_nav_single .= '<div class="link-prev"><a href="' . get_permalink( $prev_post->ID ) . '" title="' . esc_attr( $prev_post->post_title ) . '">' . __('← Previous Post', 'frontier') . '</a></div>';
    
       if ( !empty($next_post) )
          $post_nav_single .= '<div class="link-next"><a href="' . get_permalink( $next_post->ID ) . '" title="' . esc_attr( $next_post->post_title ) . '">' . __('Next Post →', 'frontier') . '</a></div>';
    
       return $post_nav_single;
    }
    add_filter( 'frontier_post_nav_single', 'custom_single_post_nav' );
  3. meravjon
    Member
    Posted 9 months ago #

    Hi ron
    Thanks for your reply. The code i paste works fine that's exactly what i wanted. I just want to add the relevant code to make it appears only on the post in the same category.
    in this link

    The right link connects to a post in a different category.

  4. ronangelo
    Member
    Theme Author

    Posted 9 months ago #

    function custom_single_post_nav( $post_nav_single ) {
       if ( is_single('328') ) {
          $prev_post = get_previous_post(true);
          $next_post = get_next_post(true);
          $post_nav_single = '';
    
          if ( !empty($prev_post) )
             $post_nav_single .= '<div class="link-prev"><a href="' . get_permalink( $prev_post->ID ) . '" title="' . esc_attr( $prev_post->post_title ) . '">' . __('← Previous Post', 'frontier') . '</a></div>';
    
          if ( !empty($next_post) )
             $post_nav_single .= '<div class="link-next"><a href="' . get_permalink( $next_post->ID ) . '" title="' . esc_attr( $next_post->post_title ) . '">' . __('Next Post →', 'frontier') . '</a></div>';
       }
       return $post_nav_single;
    }
    add_filter( 'frontier_post_nav_single', 'custom_single_post_nav' );

    328 is the Post ID.

Reply

You must log in to post.

About this Theme

About this Topic

Tags

No tags yet.