• Resolved danildilawar

    (@danildilawar)


    Hi,

    I was wondering to know that if I can change next/previous post text, for example “Next Post” change to “Next Portfolio”.

    Also if I can change it Category wise like if it’s “Portfolio” category so it shows “Next Portfolio” & if it’s “Project” category it shows “Next Project”.

    Please let me know thanks.

    Thanks,

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Jo4nny8

    (@jo4nny8)

    Hi @danildilawar

    Yes, theres a built in filter function for that. (see inside examples.txct in the plugin root) which you add to your functions.php file or similar location (I suggest a child theme)

    For your use case, you’ll need to use a conditional check for modifying the text on a per category use case.

    Something like: (not tested on a live environment so please check the code)

    function wp_post_nav_translate( $translated_text, $text, $domain ) {
    //project category
    if (is_category(‘project’)) {
    switch ( $translated_text ) {
    case ‘Category: ‘ :
    $translated_text = __( ‘Project Category: ‘, ‘wp-post-nav’ );
    break;
    case ‘Previous Post’ :
    $translated_text = __( ‘Previous Projext: ‘, ‘wp-post-nav’ );
    break;
    case ‘Next Post’ :
    $translated_text = __( ‘Next Project: ‘, ‘wp-post-nav’ );
    break;
    }
    }
    //portfolio category
    elseif (is_category(‘portfolio’)) {
    switch ( $translated_text ) {
    case ‘Category: ‘ :
    $translated_text = __( ‘Portfolio Category: ‘, ‘wp-post-nav’ );
    break;
    case ‘Previous Post’ :
    $translated_text = __( ‘Previous Portfolio: ‘, ‘wp-post-nav’ );
    break;
    case ‘Next Post’ :
    $translated_text = __( ‘Next Portfolio: ‘, ‘wp-post-nav’ );
    break;
    }
    }
    return $translated_text;
    }
    add_filter( ‘gettext’, ‘wp_post_nav_translate’, 20, 3 );

    Thread Starter danildilawar

    (@danildilawar)

    Hi John,

    I have tried this code but it is not working nothing changed. Just to add up I am using custom post type so if there is any concern with that.

    Thanks,

    Plugin Author Jo4nny8

    (@jo4nny8)

    @danildilawar

    Ah so that does make a difference as the above is for the default ‘post’ post type.

    You need to adjust it for your custom post types so instead of using the is_category wordpress filter, you need to use a post type check.

    if ( ‘portfolio’ == get_post_type() ) {
    }

    elsif ( ‘project’ == get_post_type() {
    }

    Hi John,
    We only use Tags.
    How can we change from Categogies to Tags?
    Please help.
    Thanks,
    Tony

    Plugin Author Jo4nny8

    (@jo4nny8)

    Hi @quanvan

    Thats not currently possible and is a really limited use case to work that way.

    It would require a customised solution as getting posts of the same tag is a custom query and not something that can easily be built in to the plugin.

    John

    Hi,

    Thanks for your reply.
    Can you add 2 choice:
    1. Categories
    2. Tags

    I don’t know well English so i hope you will understand mine.

    Thanks,
    Tuan Nguyen

    Thread Starter danildilawar

    (@danildilawar)

    Hi John,

    I have one custom post type & 2 different categories so I used this code but it is not working please check this code:

    
    $type = get_post_type();
    if ($type = 'astra-portfolio') {
    function wp_post_nav_translate( $translated_text, $text, $domain ) {
      //Showreel category
      if (is_category('showreel')) {
        switch ( $translated_text ) {
          case 'Category: ' :
            $translated_text = __( 'Showreel Category: ', 'wp-post-nav' );
            break;
          case 'Previous Post' :
           $translated_text = __( 'Previous Showreel: ', 'wp-post-nav' );
          break;
           case 'Next Post' :
           $translated_text = __( 'Next Showreel: ', 'wp-post-nav' );
          break;
        }
      }
      //Photographic category
      elseif (is_category('photographic')) {
        switch ( $translated_text ) {
          case 'Category: ' :
            $translated_text = __( 'Photographic Category: ', 'wp-post-nav' );
            break;
          case 'Previous Post' :
           $translated_text = __( 'Previous Photographic: ', 'wp-post-nav' );
          break;
           case 'Next Post' :
           $translated_text = __( 'Next Photographic: ', 'wp-post-nav' );
          break;
        }
      }
      return $translated_text;
    }
    add_filter( 'gettext', 'wp_post_nav_translate', 20, 3 );
    }
    

    Please let me know.

    Thanks,

    • This reply was modified 4 years, 1 month ago by Yui.
    • This reply was modified 4 years, 1 month ago by Yui. Reason: please use CODE button for proper formatting
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Next/Previous Post text change’ is closed to new replies.