纯代码实现WordPress面包屑导航

1,212次阅读
没有评论

前言

面包屑导航可以很有效的seo优化及用户体验,让用户在站内不再迷路,面包屑导航一般是:主页 – 分类 – 子分类 – 文章  可以使用模板函数实现,最好很少用插件,减少网站的请求次数及无用功能。

代码示例

<span class="token keyword def">function</span> <span class="token function">getcategory_with_child</span><span class="token punctuation">(</span><span class="token variable">$category</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token variable">$cats</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">foreach</span> <span class="token punctuation">(</span><span class="token variable">$category</span> <span class="token keyword">as</span> <span class="token variable">$cat</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$cat</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">category_parent</span><span class="token operator">!=</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token function">array_push</span><span class="token punctuation">(</span><span class="token variable">$cats</span><span class="token punctuation">,</span> <span class="token variable">$cat</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token variable">$cats</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
    
<span class="token keyword def">function</span> <span class="token function">get_category_parents_exe</span><span class="token punctuation">(</span> <span class="token variable">$id</span><span class="token punctuation">,</span> <span class="token variable">$link</span> <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token variable">$nicename</span> <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token variable">$visited</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token variable">$chains</span> <span class="token operator">=</span> <span class="token single-quoted-string string">''</span><span class="token punctuation">;</span>
    <span class="token variable">$term</span> <span class="token operator">=</span> <span class="token function">get_queried_object</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token variable">$parent</span> <span class="token operator">=</span> <span class="token function">get_term</span><span class="token punctuation">(</span> <span class="token variable">$id</span><span class="token punctuation">,</span> <span class="token variable">$term</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">taxonomy</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token function">is_wp_error</span><span class="token punctuation">(</span> <span class="token variable">$parent</span> <span class="token punctuation">)</span> <span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token variable">$parent</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token variable">$nicename</span> <span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token variable">$name</span> <span class="token operator">=</span> <span class="token variable">$parent</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">slug</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">else</span><span class="token punctuation">{</span>
        <span class="token variable">$name</span> <span class="token operator">=</span> <span class="token variable">$parent</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">name</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token variable">$parent</span><span class="token operator">-</span><span class="token operator">></span><span class="token keyword">parent</span> <span class="token operator">&&</span> <span class="token punctuation">(</span> <span class="token variable">$parent</span><span class="token operator">-</span><span class="token operator">></span><span class="token keyword">parent</span> <span class="token operator">!=</span> <span class="token variable">$parent</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">term_id</span> <span class="token punctuation">)</span> <span class="token operator">&&</span> <span class="token operator">!</span><span class="token function">in_array</span><span class="token punctuation">(</span> <span class="token variable">$parent</span><span class="token operator">-</span><span class="token operator">></span><span class="token keyword">parent</span><span class="token punctuation">,</span> <span class="token variable">$visited</span> <span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token variable">$visited</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token variable">$parent</span><span class="token operator">-</span><span class="token operator">></span><span class="token keyword">parent</span><span class="token punctuation">;</span>
        <span class="token variable">$chains</span> <span class="token punctuation">.</span><span class="token operator">=</span> <span class="token function">get_category_parents_exe</span><span class="token punctuation">(</span> <span class="token variable">$parent</span><span class="token operator">-</span><span class="token operator">></span><span class="token keyword">parent</span><span class="token punctuation">,</span> <span class="token variable">$link</span><span class="token punctuation">,</span> <span class="token variable">$nicename</span><span class="token punctuation">,</span> <span class="token variable">$visited</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token variable">$link</span> <span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token variable">$chains</span> <span class="token punctuation">.</span><span class="token operator">=</span> <span class="token variable">$name</span> <span class="token punctuation">.</span><span class="token single-quoted-string string">'__/__'</span><span class="token punctuation">.</span> <span class="token function">get_category_link</span><span class="token punctuation">(</span> <span class="token variable">$parent</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">term_id</span> <span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token single-quoted-string string">','</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">else</span><span class="token punctuation">{</span>
        <span class="token variable">$chains</span> <span class="token punctuation">.</span><span class="token operator">=</span> <span class="token variable">$name</span> <span class="token punctuation">.</span><span class="token single-quoted-string string">'__/__,'</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token variable">$chains</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token keyword def">function</span> <span class="token function">wp_breadcrumbs</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    
    <span class="token keyword">global</span> <span class="token variable">$post</span><span class="token punctuation">;</span>
    
    <span class="token variable">$breadcrumbs</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token operator">!</span><span class="token function">is_front_page</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
            <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token single-quoted-string string">'Home'</span><span class="token punctuation">,</span>
            <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">home_url</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token punctuation">)</span><span class="token punctuation">;</span>
        
        <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token function">is_home</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">__</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'Blog'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token keyword">null</span>
            <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> 
        
        <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token function">is_archive</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
            
            <span class="token variable">$post_type</span> <span class="token operator">=</span> <span class="token function">get_post_type</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token variable">$post_type_object</span> <span class="token operator">=</span> <span class="token function">get_post_type_object</span><span class="token punctuation">(</span><span class="token variable">$post_type</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token variable">$post_type_archive</span> <span class="token operator">=</span> <span class="token function">get_post_type_archive_link</span><span class="token punctuation">(</span><span class="token variable">$post_type</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$post_type_object</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">labels</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">name</span><span class="token punctuation">,</span>
                <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$post_type_archive</span>
            <span class="token punctuation">)</span><span class="token punctuation">;</span>
            
            <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">is_category</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">||</span> <span class="token function">is_tax</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                <span class="token variable">$term</span> <span class="token operator">=</span> <span class="token function">get_queried_object</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                
                <span class="token variable">$get_term_parents</span> <span class="token operator">=</span> <span class="token function">get_category_parents_exe</span><span class="token punctuation">(</span><span class="token variable">$term</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">term_id</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token variable">$get_term_parents</span> <span class="token operator">=</span> <span class="token function">rtrim</span><span class="token punctuation">(</span><span class="token variable">$get_term_parents</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">','</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token variable">$term_parents</span> <span class="token operator">=</span> <span class="token function">explode</span><span class="token punctuation">(</span><span class="token single-quoted-string string">','</span><span class="token punctuation">,</span> <span class="token variable">$get_term_parents</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token variable">$terms_count</span> <span class="token operator">=</span> <span class="token function">count</span><span class="token punctuation">(</span><span class="token variable">$term_parents</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token keyword">foreach</span><span class="token punctuation">(</span><span class="token variable">$term_parents</span> <span class="token keyword">as</span> <span class="token variable">$key</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$parents</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    <span class="token variable">$parents</span> <span class="token operator">=</span> <span class="token function">explode</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'__/__'</span><span class="token punctuation">,</span> <span class="token variable">$parents</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$key</span> <span class="token operator"><</span> <span class="token variable">$terms_count</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                        <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                                <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$parents</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
                                <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span>  <span class="token variable">$parents</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span>
                        <span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
                        <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                                <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$parents</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
                                <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token keyword">null</span>
                        <span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token punctuation">}</span>
                <span class="token punctuation">}</span>
                
            <span class="token punctuation">}</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token function">is_tag</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                    <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">single_tag_title</span><span class="token punctuation">(</span><span class="token single-quoted-string string">''</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token keyword">null</span>
                <span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token function">is_author</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">global</span> <span class="token variable">$author</span><span class="token punctuation">;</span>
                <span class="token variable">$userdata</span> <span class="token operator">=</span> <span class="token function">get_userdata</span><span class="token punctuation">(</span> <span class="token variable">$author</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                    <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">__</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'Author: '</span><span class="token punctuation">)</span> <span class="token punctuation">.</span> <span class="token variable">$userdata</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">display_name</span><span class="token punctuation">,</span>
                    <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token keyword">null</span>
                <span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span> 
            
            <span class="token keyword">if</span><span class="token punctuation">(</span> <span class="token function">is_day</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                    <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_the_time</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'Y'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_year_link</span><span class="token punctuation">(</span> <span class="token function">get_the_time</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'Y'</span><span class="token punctuation">)</span> <span class="token punctuation">)</span>
                <span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                    <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_the_time</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'M'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_month_link</span><span class="token punctuation">(</span> <span class="token function">get_the_time</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'Y'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">get_the_time</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'m'</span><span class="token punctuation">)</span> <span class="token punctuation">)</span>
                <span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                    <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_the_time</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'jS'</span><span class="token punctuation">)</span> <span class="token punctuation">.</span> <span class="token single-quoted-string string">' '</span> <span class="token punctuation">.</span> <span class="token function">get_the_time</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'M'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token keyword">null</span>
                <span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            
            <span class="token keyword">if</span><span class="token punctuation">(</span> <span class="token function">is_month</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                    <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_the_time</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'Y'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_year_link</span><span class="token punctuation">(</span> <span class="token function">get_the_time</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'Y'</span><span class="token punctuation">)</span> <span class="token punctuation">)</span>
                <span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                    <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_the_time</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'M'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token keyword">null</span>
                <span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            
            <span class="token keyword">if</span><span class="token punctuation">(</span> <span class="token function">is_year</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                    <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_the_time</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'Y'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token keyword">null</span>
                <span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        
        <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token function">get_query_var</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'paged'</span><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
            
            <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token operator">!</span> <span class="token function">is_archive</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                    <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_post_type_object</span><span class="token punctuation">(</span><span class="token function">get_post_type</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">labels</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">singular_name</span><span class="token punctuation">,</span>
                    <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_post_type_archive_link</span><span class="token punctuation">(</span><span class="token function">get_post_type_object</span><span class="token punctuation">(</span><span class="token function">get_post_type</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">query_var</span><span class="token punctuation">)</span>
                <span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            
            <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">__</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'Page '</span><span class="token punctuation">)</span> <span class="token punctuation">.</span> <span class="token function">get_query_var</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'paged'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token keyword">null</span>
            <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> 
        
         <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token function">is_search</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
             <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">__</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'Search results for '</span><span class="token punctuation">)</span> <span class="token punctuation">.</span> <span class="token function">get_search_query</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token keyword">null</span>
            <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> 
        
        <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token function">is_404</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">__</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'Error 404'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token keyword">null</span>
            <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        
        <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">is_singular</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            
            <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">is_single</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                
                <span class="token variable">$post_type</span> <span class="token operator">=</span> <span class="token function">get_post_type</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token variable">$post_type_object</span> <span class="token operator">=</span> <span class="token function">get_post_type_object</span><span class="token punctuation">(</span><span class="token variable">$post_type</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token variable">$post_type_archive</span> <span class="token operator">=</span> <span class="token function">get_post_type_archive_link</span><span class="token punctuation">(</span><span class="token variable">$post_type</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                    <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$post_type_object</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">labels</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">name</span><span class="token punctuation">,</span>
                    <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$post_type_archive</span>
                <span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token variable">$term</span> <span class="token operator">=</span> <span class="token function">get_the_category</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token operator">!</span><span class="token function">empty</span><span class="token punctuation">(</span><span class="token variable">$term</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    <span class="token variable">$term_wc</span> <span class="token operator">=</span> <span class="token function">getcategory_with_child</span><span class="token punctuation">(</span><span class="token variable">$term</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token operator">!</span><span class="token function">empty</span><span class="token punctuation">(</span><span class="token variable">$term_wc</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                        <span class="token variable">$term</span> <span class="token operator">=</span> <span class="token variable">$term_wc</span><span class="token punctuation">;</span>
                    <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
                        <span class="token variable">$term</span> <span class="token operator">=</span> <span class="token variable">$term</span><span class="token punctuation">;</span>
                    <span class="token punctuation">}</span>
                    <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token operator">!</span><span class="token function">empty</span><span class="token punctuation">(</span><span class="token variable">$term</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                        <span class="token variable">$term</span> <span class="token operator">=</span> <span class="token variable">$term</span><span class="token punctuation">[</span><span class="token function">count</span><span class="token punctuation">(</span><span class="token variable">$term</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
                        
                        <span class="token variable">$get_term_parents</span> <span class="token operator">=</span> <span class="token function">get_category_parents_exe</span><span class="token punctuation">(</span><span class="token variable">$term</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">term_id</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                        <span class="token variable">$get_term_parents</span> <span class="token operator">=</span> <span class="token function">rtrim</span><span class="token punctuation">(</span><span class="token variable">$get_term_parents</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">','</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                        <span class="token variable">$term_parents</span> <span class="token operator">=</span> <span class="token function">explode</span><span class="token punctuation">(</span><span class="token single-quoted-string string">','</span><span class="token punctuation">,</span> <span class="token variable">$get_term_parents</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                        <span class="token keyword">foreach</span><span class="token punctuation">(</span><span class="token variable">$term_parents</span> <span class="token keyword">as</span> <span class="token variable">$parents</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                            <span class="token variable">$parents</span> <span class="token operator">=</span> <span class="token function">explode</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'__/__'</span><span class="token punctuation">,</span> <span class="token variable">$parents</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                            <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                                <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$parents</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
                                <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$parents</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span>
                            <span class="token punctuation">)</span><span class="token punctuation">;</span>
                        <span class="token punctuation">}</span>
                        
                        
                    <span class="token punctuation">}</span>
                <span class="token punctuation">}</span>
                
                <span class="token variable">$taxonomy</span> <span class="token operator">=</span> <span class="token single-quoted-string string">'product_cat'</span><span class="token punctuation">;</span>
                <span class="token variable">$taxonomy_exists</span> <span class="token operator">=</span> <span class="token function">taxonomy_exists</span><span class="token punctuation">(</span><span class="token variable">$taxonomy</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">empty</span><span class="token punctuation">(</span><span class="token variable">$term</span><span class="token punctuation">)</span> <span class="token operator">&&</span> <span class="token variable">$taxonomy_exists</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    
                    <span class="token variable">$taxonomy_terms</span> <span class="token operator">=</span> <span class="token function">get_the_terms</span><span class="token punctuation">(</span> <span class="token variable">$post</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">ID</span><span class="token punctuation">,</span> <span class="token variable">$taxonomy</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token variable">$base_tex</span> <span class="token operator">=</span> <span class="token variable">$taxonomy_terms</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
                    <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">count</span><span class="token punctuation">(</span><span class="token variable">$taxonomy_terms</span><span class="token punctuation">)</span> <span class="token operator">></span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                        <span class="token variable">$term</span> <span class="token operator">=</span> <span class="token function">get_term</span><span class="token punctuation">(</span> <span class="token variable">$taxonomy_terms</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token operator">-</span><span class="token operator">></span><span class="token keyword">parent</span><span class="token punctuation">,</span> <span class="token variable">$taxonomy</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
                        
                        <span class="token variable">$get_term_parents</span> <span class="token operator">=</span> <span class="token function">get_category_parents_exe</span><span class="token punctuation">(</span><span class="token variable">$term</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">term_id</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                        <span class="token variable">$get_term_parents</span> <span class="token operator">=</span> <span class="token function">rtrim</span><span class="token punctuation">(</span><span class="token variable">$get_term_parents</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">','</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                        <span class="token variable">$term_parents</span> <span class="token operator">=</span> <span class="token function">explode</span><span class="token punctuation">(</span><span class="token single-quoted-string string">','</span><span class="token punctuation">,</span> <span class="token variable">$get_term_parents</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                        <span class="token keyword">foreach</span><span class="token punctuation">(</span><span class="token variable">$term_parents</span> <span class="token keyword">as</span> <span class="token variable">$parents</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                            <span class="token variable">$parents</span> <span class="token operator">=</span> <span class="token function">explode</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'__/__'</span><span class="token punctuation">,</span> <span class="token variable">$parents</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                            <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                                <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$parents</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
                                <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$parents</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span>
                            <span class="token punctuation">)</span><span class="token punctuation">;</span>
                        <span class="token punctuation">}</span>
                        
                    <span class="token punctuation">}</span>
                    
                    <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                        <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$base_tex</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">name</span><span class="token punctuation">,</span>
                        <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_term_link</span><span class="token punctuation">(</span> <span class="token variable">$base_tex</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">term_id</span> <span class="token punctuation">)</span>
                    <span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
                <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                    <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_the_title</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token keyword">null</span>
                <span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            
            <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">is_page</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                
                  <span class="token keyword">if</span><span class="token punctuation">(</span> <span class="token variable">$post</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">post_parent</span> <span class="token punctuation">)</span><span class="token punctuation">{</span>
                    <span class="token variable">$anc</span> <span class="token operator">=</span> <span class="token function">get_post_ancestors</span><span class="token punctuation">(</span> <span class="token variable">$post</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">ID</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token variable">$anc</span> <span class="token operator">=</span> <span class="token function">array_reverse</span><span class="token punctuation">(</span><span class="token variable">$anc</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token operator">!</span><span class="token function">isset</span><span class="token punctuation">(</span> <span class="token variable">$parents</span> <span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token variable">$parents</span> <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
                    <span class="token keyword">foreach</span> <span class="token punctuation">(</span> <span class="token variable">$anc</span> <span class="token keyword">as</span> <span class="token variable">$ancestor</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
                        <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                            <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_the_title</span><span class="token punctuation">(</span><span class="token variable">$ancestor</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                            <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_permalink</span><span class="token punctuation">(</span><span class="token variable">$ancestor</span><span class="token punctuation">)</span>
                        <span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token punctuation">}</span>
                    <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                        <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_the_title</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                        <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token keyword">null</span>
                    <span class="token punctuation">)</span><span class="token punctuation">;</span>
                    
                <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
                    <span class="token variable">$breadcrumbs</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
                        <span class="token single-quoted-string string">'title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">get_the_title</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                        <span class="token single-quoted-string string">'link'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token keyword">null</span>
                    <span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
    
    <span class="token variable">$output</span> <span class="token operator">=</span> <span class="token single-quoted-string string">''</span><span class="token punctuation">;</span>
    <span class="token variable">$output</span> <span class="token punctuation">.</span><span class="token operator">=</span> <span class="token single-quoted-string string">'<ol class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList">'</span><span class="token punctuation">;</span>
    <span class="token variable">$breadcrumbs</span> <span class="token operator">=</span> <span class="token function">array_combine</span><span class="token punctuation">(</span><span class="token function">range</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token function">count</span><span class="token punctuation">(</span><span class="token variable">$breadcrumbs</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token variable">$breadcrumbs</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">foreach</span> <span class="token punctuation">(</span><span class="token variable">$breadcrumbs</span> <span class="token keyword">as</span> <span class="token variable">$key</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token variable">$breadcrumb</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token variable">$output</span> <span class="token punctuation">.</span><span class="token operator">=</span> <span class="token single-quoted-string string">'<li class="breadcrumb-item" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">'</span><span class="token punctuation">;</span> 
        <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token operator">!</span><span class="token function">empty</span><span class="token punctuation">(</span><span class="token variable">$breadcrumb</span><span class="token punctuation">[</span><span class="token single-quoted-string string">'link'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span> 
            <span class="token variable">$output</span> <span class="token punctuation">.</span><span class="token operator">=</span> <span class="token single-quoted-string string">'<a itemprop="item" href="'</span><span class="token punctuation">.</span><span class="token variable">$breadcrumb</span><span class="token punctuation">[</span><span class="token single-quoted-string string">'link'</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token single-quoted-string string">'">'</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token variable">$output</span> <span class="token punctuation">.</span><span class="token operator">=</span> <span class="token single-quoted-string string">'<span itemprop="name">'</span><span class="token punctuation">.</span><span class="token variable">$breadcrumb</span><span class="token punctuation">[</span><span class="token single-quoted-string string">'title'</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token single-quoted-string string">'</span>'</span><span class="token punctuation">;</span> 
        <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token operator">!</span><span class="token function">empty</span><span class="token punctuation">(</span><span class="token variable">$breadcrumb</span><span class="token punctuation">[</span><span class="token single-quoted-string string">'link'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token variable">$output</span> <span class="token punctuation">.</span><span class="token operator">=</span> <span class="token single-quoted-string string">'</a>'</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token variable">$output</span> <span class="token punctuation">.</span><span class="token operator">=</span> <span class="token single-quoted-string string">'<meta itemprop="position" content="'</span><span class="token punctuation">.</span><span class="token variable">$key</span><span class="token punctuation">.</span><span class="token single-quoted-string string">'" />'</span><span class="token punctuation">;</span>
        <span class="token variable">$output</span> <span class="token punctuation">.</span><span class="token operator">=</span> <span class="token single-quoted-string string">'</li> '</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token variable">$output</span> <span class="token punctuation">.</span><span class="token operator">=</span> <span class="token single-quoted-string string">'</ol>'</span><span class="token punctuation">;</span>
    <span class="token keyword">echo</span>  <span class="token variable">$output</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

调用示例

<span class="token php language-php"><span class="token delimiter important"><?php</span> <span class="token keyword keyword-if">if</span><span class="token punctuation">(</span><span class="token function">function_exists</span><span class="token punctuation">(</span><span class="token string">'wp_breadcrumbs'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token function">wp_breadcrumbs</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token delimiter important">?></span></span>

使用方法

代码示例放在主题文件的function.php下,调用示例放在头部文件的显示位置(自行定义)。

评论(没有评论)