• Resolved hiyoro

    (@hiyoro)


    [1] URL of archive with custom post type
    example.com/[post_type]/

    [2] URL for monthly archives with custom post type
    example.com/[post_type]/[yyyy]/[mm]/

    The URL to link to the Breadcrumb NavXT monthly archive displayed at the URL in [2] will look like this
    example.com/yyyy/?post_type=[post_type]

    It works as a URL, but could it be modified as follows?
    example.com/[post_type]/[yyyy]/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author John Havlik

    (@mtekk)

    Currently, your best bet is to modify the URL using the bcn_breadcrumb_url filter.

    From the Breadcrumb NavXT side, I should probably revisit the code that is adding that query arg and make sure there isn’t a better way of doing it (which would tie into the rewrite system so it would just ‘know’ you have a post_type rewrite in your permalink structure).

    Thread Starter hiyoro

    (@hiyoro)

    Thank you very much!

    <font style=”vertical-align: inherit;”><font style=”vertical-align: inherit;”>教えていただいた URL を使用して、functions.php に次のコードを追加することで、期待どおりの結果を得ることができました。</font></font>

    add_filter('bcn_breadcrumb_url', 'my_breadcrumb_url_changer', 3, 10);
    function my_breadcrumb_url_changer($url, $type, $id)
    {
        //Determining Custom Post Types
        $post_type = get_query_var('post_type');
        if ($post_type) {
            $dir = $post_type . '/';
        } else {
            $dir = '/';
        }
    
        //Fix URL when $type is archive by year
        if (in_array('date-year', $type)) {
            return home_url() . '/' . $dir . date('Y') . '/';
        }
    
        return $url;
    }
    • This reply was modified 1 year, 6 months ago by hiyoro. Reason: resolved
    Thread Starter hiyoro

    (@hiyoro)

    There was a bug in the posted code, which has been corrected.

    if (function_exists('bcn_display')) {
        add_filter('bcn_breadcrumb_url', 'my_breadcrumb_url_changer', 3, 10);
        function my_breadcrumb_url_changer($url, $type, $id)
        {
            //Determining Custom Post Types
            $post_type = get_query_var('post_type');
            if ($post_type) {
                $dir = $post_type . '/';
            } else {
                $dir = '/';
            }
    
            //Fix URL when $type is archive by year
            if (in_array('date-year', $type)) {
                return home_url() . '/' . $dir . get_query_var('year') . '/';
            }
    
            return $url;
        }
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘URL notation to custom post type archives by year becomes URL with parameters’ is closed to new replies.