パンくずリストの作成
-2015年07月07日-
functions.phpに下記を書き足す。
5 | if (!is_home()&&!is_admin()){ |
7 | $str .= '<a href="' . home_url() . '" itemprop="url"><span itemprop="title">ホーム</span></a> ></div>' ; |
10 | $cat = get_queried_object(); |
11 | if ( $cat -> parent != 0){ |
12 | $ancestors = array_reverse (get_ancestors( $cat -> cat_ID, 'category' )); |
13 | foreach ( $ancestors as $ancestor ){ |
14 | $str .= '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="' . get_category_link( $ancestor ) . '" itemprop="url"><span itemprop="title">' . get_cat_name( $ancestor ) . '</span></a> ></div>' ; |
17 | $str .= '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="' . get_category_link( $cat -> term_id). '" itemprop="url"><span itemprop="title">' . $cat -> cat_name . '</span></a></div>' ; |
19 | if ( $post -> post_parent != 0 ){ |
20 | $ancestors = array_reverse (get_post_ancestors( $post ->ID )); |
21 | foreach ( $ancestors as $ancestor ){ |
22 | $str .= '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="' . get_permalink( $ancestor ). '" itemprop="url"><span itemprop="title">' . get_the_title( $ancestor ) . '</span></a></div>' ; |
25 | } elseif (is_single()){ |
26 | $categories = get_the_category( $post ->ID); |
27 | $cat = $categories [0]; |
28 | if ( $cat -> parent != 0){ |
29 | $ancestors = array_reverse (get_ancestors( $cat -> cat_ID, 'category' )); |
30 | foreach ( $ancestors as $ancestor ){ |
31 | $str .= '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="' . get_category_link( $ancestor ). '" itemprop="url"><span itemprop="title">' . get_cat_name( $ancestor ). '</span></a> ></div>' ; |
34 | $str .= '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="' . get_category_link( $cat -> term_id). '" itemprop="url"><span itemprop="title">' . $cat -> cat_name . '</span></a></div>' ; |
36 | $str .= '<div>' . wp_title( '' , false) . '</div>' ; |
パンくずリストを表示したいところに書きを書き足す。
一列に表示をしたかったらcssに書き込む