<?php /* 構造化データ */
if ( is_front_page() && is_home() ) {
// デフォルトホームページ
/* ################################################################ */
?>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"item": {
"@id": "<?php echo home_url(); ?>",
"name": "トップ"
}
},
<?php
foreach ( array_reverse(get_post_ancestors($post->ID)) as $parid ) { ?>
{
"@type": "ListItem",
"position": 2,
"item": {
"@id": "<?php echo get_page_link( $parid );?>",
"name": "<?php echo get_page($parid)->post_title; ?>"
}
},
<?php } ?>
{
"@type": "ListItem",
"position": <?php echo (is_page() && $post->post_parent) ? 3: 2; ?>,
"item": {
"@id": "<?php echo get_the_permalink(); ?>",
"name": "<?php the_title(''); ?>"
}
}
]
}
</script>
<?php
} elseif ( is_front_page() ) {
// 固定ペーシを使ったホームページ
/* ################################################################ */
?>
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "Restaurant",
"name" : "お店の名前",
"url": "<?php echo get_the_permalink(); ?>",
"priceRange": "5000",
"currenciesAccepted": "JPY",
"openingHoursSpecification": [{
"@type": "OpeningHoursSpecification",
"dayOfWeek": [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
],
"opens": "16:00",
"closes": "00:00"
},{
"@type": "OpeningHoursSpecification",
"dayOfWeek": [
"Sunday",
"PublicHolidays"
],
"opens": "16:00",
"closes": "23:30"
}],
"acceptsReservations": "True",
"image" : "お店イメージ画像のURL",
"telephone" : "052-231-1700",
"address" : {
"@type" : "PostalAddress",
"streetAddress" : "本丸1-1",
"addressLocality" : "名古屋市 中区",
"addressRegion" : "愛知県",
"postalCode": "460-0031",
"addressCountry": "JP"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 35.1856557,
"longitude": 136.9013576
},
"menu" : "メニューのURL",
"servesCuisine" : "和食,定食,日本料理"
}
</script>
<?php
} elseif ( is_home() ) {
// ブログページ
/* ################################################################ */
?>
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "Restaurant",
"name" : "お店の名前",
"url": "<?php echo get_the_permalink(); ?>",
"priceRange": "5000",
"currenciesAccepted": "JPY",
"openingHoursSpecification": [{
"@type": "OpeningHoursSpecification",
"dayOfWeek": [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
],
"opens": "16:00",
"closes": "00:00"
},{
"@type": "OpeningHoursSpecification",
"dayOfWeek": [
"Sunday",
"PublicHolidays"
],
"opens": "16:00",
"closes": "23:30"
}],
"acceptsReservations": "True",
"image" : "お店イメージ画像のURL",
"telephone" : "052-231-1700",
"address" : {
"@type" : "PostalAddress",
"streetAddress" : "本丸1-1",
"addressLocality" : "名古屋市 中区",
"addressRegion" : "愛知県",
"postalCode": "460-0031",
"addressCountry": "JP"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 35.1856557,
"longitude": 136.9013576
},
"menu" : "メニューのURL",
"servesCuisine" : "和食,定食,日本料理"
}
</script>
<?php
} elseif (is_single()) {
//個別投稿ページ
/* ################################################################ */
?>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BlogPosting",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "<?php echo get_the_permalink(); ?>"
},
"headline": "<?php stripslashes(htmlspecialchars(the_title_attribute(), ENT_QUOTES|ENT_HTML5)); ?>",
"description": "<?php echo stripslashes(htmlspecialchars(wp_trim_words( $post->post_content, 100, '…'), ENT_QUOTES|ENT_HTML5)); ?>",
"datePublished": "<?php echo get_date_from_gmt(get_post_time('c', true), 'c'); ?>",
"dateModified": "<?php echo get_date_from_gmt(get_post_modified_time('c', true), 'c'); ?>",
"author": {
"@type": "Person",
"name": "自分の名前"
},
"publisher": {
"@type": "Organization",
"name": "お店の名前、またはグループ会社の名前",
"url": "お店のURL、又はグループ会社のURL",
"logo": {
"@type": "ImageObject",
"url": "お店の画像URL、またはグループ会社のURL",
"width": 200,
"height": 200
},
"address": {
"@type" : "PostalAddress",
"streetAddress" : "本丸1-1",
"addressLocality" : "名古屋市 中区",
"addressRegion" : "愛知県",
"postalCode": "460-0031",
"addressCountry": "JP"
}
},
"image": {
"@type": "ImageObject",
<?php
/* アイキャッチ画像の要素を取り出す */
$thumb_id = get_post_thumbnail_id();
if (has_post_thumbnail()) { //アイキャッチ画像を設定している場合
$thumb_img = wp_get_attachment_image_src($thumb_id, 'full');
} else { //アイキャッチ画像を設定していない場合
$thumb_img[0] = "お店のロゴ画像URL";
$thumb_img[1] = "200";
$thumb_img[2] = "200";
} ?>
"url": "<?php echo $thumb_img[0]; ?>",
"width": <?php echo $thumb_img[1]; ?>,
"height": <?php echo $thumb_img[2]; ?>
}
}
</script>
<?php
} else {
// それ以外
/* ################################################################ */
?>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"item": {
"@id": "<?php echo home_url(); ?>",
"name": "トップ"
}
},
<?php
foreach ( array_reverse(get_post_ancestors($post->ID)) as $parid ) { ?>
{
"@type": "ListItem",
"position": 2,
"item": {
"@id": "<?php echo get_page_link( $parid );?>",
"name": "<?php echo get_page($parid)->post_title; ?>"
}
},
<?php } ?>
{
"@type": "ListItem",
"position": <?php echo (is_page() && $post->post_parent) ? 3: 2; ?>,
"item": {
"@id": "<?php echo get_the_permalink(); ?>",
"name": "<?php the_title(''); ?>"
}
}
]
}
</script>
<?php
}
/* 構造化データ ここまで */ ?>