WordPressを入れ直したので、外観-テーマをTwenty Seventeenに変更しました。
それに伴い、デザインをカスタマイズしています。
-
アーカイブを変更
トップページが全文表示から抜粋表示に変更となります。
archive.php1
get_template_part( 'template-parts/post/content', get_post_format() );
2
↓
3
get_template_part( 'template-parts/post/content', 'excerpt' );
-
「投稿」文字を削除
記事の上にある「投稿」の文字を削除します。
index.php1
以下を削除
2
<
header
class
=
"page-header"
>
3
<
h2
class
=
"page-title"
><?
php
_e( 'Posts', 'twentyseventeen' ); ?></
h2
>
4
</
header
>
-
「カテゴリ」文字を削除
記事の上にある「カテゴリ」の文字を削除します。
archive.php1
以下を削除
2
<?
php
if ( have_posts() ) : ?>
3
<
header
class
=
"page-header"
>
4
<?
php
5
the_archive_title( '<h1
class
=
"page-title"
>', '</
h1
>' );
6
the_archive_description( '<
div
class
=
"taxonomy-description"
>', '</
div
>' );
7
?>
8
</
header
>
<!-- .page-header -->
9
<?
php
endif; ?>
-
パンくずリストの追加(未実施)
fanction.php1
以下を一番下に追加
2
function breadcrumb(){
3
global $post;$str ='';
4
if(!is_home()&&!is_admin()){
5
$str.= '<
div
id
=
"breadcrumb"
class
=
"cf"
><
div
itemscope
itemtype
=
"http://data-vocabulary.org/Breadcrumb"
style
=
"display:table-cell;"
>';
6
$str.= '<
a
href
=
"'. home_url() .'"
itemprop
=
"url"
><
span
itemprop
=
"title"
>ホーム</
span
></
a
> > </
div
>';
7
if(is_category()) {
8
$cat = get_queried_object();
9
if($cat -> parent != 0){
10
$ancestors = array_reverse(get_ancestors( $cat -> cat_ID, 'category' ));
11
foreach($ancestors as $ancestor){
12
$str.='<
div
itemscope
itemtype
=
"http://data-vocabulary.org/Breadcrumb"
style
=
"display:table-cell;"
><
a
href
=
"'. get_category_link($ancestor) .'"
itemprop
=
"url"
><
span
itemprop
=
"title"
>'. get_cat_name($ancestor) .'</
span
></
a
> > </
div
>';
13
}
14
}
15
$str.='<
div
itemscope
itemtype
=
"http://data-vocabulary.org/Breadcrumb"
style
=
"display:table-cell;"
><
a
href="'. get_category_link($cat -> term_id). '" itemprop="url"><
span
itemprop
=
"title"
>'. $cat-> cat_name . '</
span
></
a
> > </
div
>';
16
}elseif(is_page()){
17
if($post -> post_parent != 0 ){
18
$ancestors = array_reverse(get_post_ancestors( $post->ID ));
19
foreach($ancestors as $ancestor){
20
$str.='<
div
itemscope
itemtype
=
"http://data-vocabulary.org/Breadcrumb"
style
=
"display:table-cell;"
><
a
href
=
"'. get_permalink($ancestor).'"
itemprop
=
"url"
><
span
itemprop
=
"title"
>'. get_the_title($ancestor) .'</
span
></
a
> > </
div
>';
21
}
22
}
23
}elseif(is_single()){
24
$categories = get_the_category($post->ID);
25
$cat = $categories[0];
26
if($cat -> parent != 0){
27
$ancestors = array_reverse(get_ancestors( $cat -> cat_ID, 'category' ));
28
foreach($ancestors as $ancestor){
29
$str.='<
div
itemscope
itemtype
=
"http://data-vocabulary.org/Breadcrumb"
style
=
"display:table-cell;"
><
a
href
=
"'. get_category_link($ancestor).'"
itemprop
=
"url"
><
span
itemprop
=
"title"
>'. get_cat_name($ancestor). '</
span
></
a
>→</
div
>';
30
}
31
}
32
$str.='<
div
itemscope
itemtype
=
"http://data-vocabulary.org/Breadcrumb"
style
=
"display:table-cell;"
><
a
href="'. get_category_link($cat -> term_id). '" itemprop="url"><
span
itemprop
=
"title"
>'. $cat-> cat_name . '</
span
></
a
> > </
div
>';
33
}else{
34
$str.='<
div
>'. wp_title('', false) .'</
div
>';
35
}
36
$str.='</
div
>';
37
}
38
echo $str;
39
}
1
以下をパンくずリストを表示したいphp(page.phpやsingle.phpなど)に追加
2
<?
php
breadcrumb(); ?>