Support » Plugin: Automatically Hierarchic Categories in Menu » Custom taxonomies base permalink fix

  • Resolved Art Project Group

    (@artprojectgroup)


    Please, add this code to your /includes/class-auto-hierarchic-category-menu.php file. Line 226:

    			else{
                    global $wp_rewrite;
    
                    $termlink = $wp_rewrite->get_extra_permastruct( $attr[ 'taxonomy' ] );
                    $link_sub = str_replace( "/%{$attr[ 'taxonomy' ]}%", '', $termlink );
                }
    

    This code add the base permalink to custom taxonomies. Tested and working.

    And fix line 249:

    						$link=$slug.'/'.$category->slug.($params['linkget']?'?'.$params['linkget']:'');
    

    Or add a new option to your shortcode to use the trailing slash or not. Not all websites use the trailing slash. We never use it.

    Best regards.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Atakan Au

    (@atakanau)

    Thanks for your contribution.
    As you suggested, I updated the code for permalinks. I added new parameter, t_slash=0 option can be used to remove trailing slash. I have committed the changes to the development version. Please test it and let me know if it works.

    Thread Starter Art Project Group

    (@artprojectgroup)

    Sorry but Sorry but you have an issue on line 230 that causes double slash to be added.

    Change this:
    $link_sub = '/'.str_replace( "/%{$attr[ 'taxonomy' ]}%", '', $termlink );

    To this:
    $link_sub = str_replace( "/%{$attr[ 'taxonomy' ]}%", '', $termlink );

    The $termlink variable includes the slash.

    Best regards.

    Thread Starter Art Project Group

    (@artprojectgroup)

    Sorry but the new version breaks links to product categories if we remove the initial slash.

    Let me see if I can find a solution for you.

    Best regards.

    Thread Starter Art Project Group

    (@artprojectgroup)

    Fixed!

    New code in line 230:

    $link_sub = str_replace( "/%{$attr[ 'taxonomy' ]}%", '', $termlink );
    $link_sub = ( strpos( $link_sub, '/' ) === 0 ) ? $link_sub : '/' . $link_sub;
    

    Works ALWAYS!

    Best regards.

    Plugin Author Atakan Au

    (@atakanau)

    The $termlink variable does not start with '/' in my test. Let’s solve it like this:

    $link_sub = '/'.ltrim(str_replace( "/%{$attr[ 'taxonomy' ]}%", '', $termlink ), '/');

    Thread Starter Art Project Group

    (@artprojectgroup)

    No, use my last code, please:

    $link_sub = str_replace( "/%{$attr[ 'taxonomy' ]}%", '', $termlink );
    $link_sub = ( strpos( $link_sub, '/' ) === 0 ) ? $link_sub : '/' . $link_sub;

    With custom taxonomies start with slash. You need only with product categories.

    With this code the slash is added when the variable doesn’t begin with it. Please test it.

    Best regards.

    Plugin Author Atakan Au

    (@atakanau)

    You’re right. But both code give the same result. Is not it?

    Thread Starter Art Project Group

    (@artprojectgroup)

    Yes.

    This line:

    $link_sub = ( strpos( $link_sub, '/' ) === 0 ) ? $link_sub : '/' . $link_sub;
    

    checks whether $link_sub starts with slash or not and adds it in case it does not start with it. This way /taxonomy-base is always returned.

    Best regards.

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