WordPress

posty — Jak wyświetlić nawigację w kategorii?

  • 22 maja, 2024
  • 3 min read
posty — Jak wyświetlić nawigację w kategorii?


Mam menu nawigacyjne wyświetlane na wszystkich typach treści (stronach, postach, stronie głównej itp.) – obok kategorii. Jaki jest sposób dodania kategorii do typów treści, gdzie wyświetlana jest bułka tarta?

To jest kod nawigacyjny z mojego plikufunction.php:

function asap_breadcrumbs_pages($post,$schema)
{

    if ( ! get_theme_mod('asap_hide_breadcrumb_page') && ! get_post_meta( get_the_ID(), 'hide_breadcrumbs', true ) )
    {
        
        $url_pillar_page = get_post_meta(get_the_ID() , 'single_bc_url_pillar_page', true);

        $text_pillar_page = get_post_meta(get_the_ID() , 'single_bc_text_pillar_page', true);

        $post_title = get_post_meta(get_the_ID() , 'single_bc_text', true) ? : get_the_title();

        $label = get_theme_mod('asap_breadcrumb_text') ? : get_bloginfo('name');

        if ($schema)
        {
            $format="<li itemprop="itemListElement" itemscope itemtype=" href="%s" title="%s" itemprop="item"><span itemprop="name">%s</span></a><meta itemprop="position" content="%s"></li>";
        }
        else
        {
            $format="<li><a href="%s" title="%s"><span>%s</span></a></li>";
        }

        if ($url_pillar_page && $text_pillar_page)
        {
            $count = 3;
        }
        else
        {
            $anc = array_map('get_post', array_reverse((array)get_post_ancestors($post)));

            $count = count($anc);

            $count = $count + 2;

            $links = array_map('get_permalink', $anc);

        }

        if ($schema)
        {
            printf('<div role="navigation" aria-label="Breadcrumbs" class="breadcrumb-trail breadcrumbs" itemprop="breadcrumb">');

            printf('<ul class="breadcrumb" itemscope itemtype="

            printf('<meta name="numberOfItems" content="' . $count . '">');

            printf('<meta name="itemListOrder" content="Ascending">');

            printf('<li itemprop="itemListElement" itemscope itemtype=" href="%s" itemprop="item"><span itemprop="name">' . $label . '</span></a><meta itemprop="position" content="1"></li>', esc_url(home_url()));
        }
        else
        {
            printf('<div class="breadcrumb-trail breadcrumbs">');

            printf('<ul class="breadcrumb">');

            printf('<li><a href="%s"><span>' . $label . '</span></a></li>', esc_url(home_url()));
        }

        $meta = 2;

        if ($url_pillar_page && $text_pillar_page)
        {
            printf($format, $url_pillar_page, $text_pillar_page, $text_pillar_page, $meta);

            $meta = $meta + 1;
        }
        else
        {
            foreach ($anc as $i => $apost)
            {
                
                $title = get_post_meta( $apost->ID , 'single_bc_text', true);
            
                if ( ! $title ) {

                $title = apply_filters('the_title', $apost->post_title);
                    
                }

                printf($format, $links[$i], esc_attr($title) , esc_html($title) , $meta);

                $meta = $meta + 1;
            }

        }

        if ($schema)
        {
            echo '<li itemprop="itemListElement" itemscope itemtype=" itemprop="name">' . $post_title . '</span><meta itemprop="position" content="' . $meta . '"></li>';
        }
        else
        {
            echo '<li><span>' . $post_title . '</span></li>';
        }

        printf('</ul>');

        printf('</div>');
        
    }
    
}


Źródło

Warto przeczytać!  Jak zatrzymać lustrzane odbicie zdarzeń JS w krótkich kodach umieszczonych na tej samej stronie?