こんにちは
home.php、index.php より前に実行されるコード(header.php や functions.php、プラグインなど)のどこかに問題(wp_reset_postdata() の記入漏れとか・・・)があると思われます。
header.php はどのようなコードでしょうか?
ありがとうございます。header。PHPは以下です。
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>" type="text/css" media="screen" >
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:title" content="<?php echo bloginfo( 'name' );?>" />
<meta property="og:description" content="<?php
if(is_home()){
echo bloginfo('description'); //ブログ説明表示
}else{
if( is_page( 'memo , portfolio , contact' )){
echo category_description();//カテゴリ説明表示
}else{
if(mb_strlen($post->post_content,'UTF-8')>120){
$content = mb_substr($post->post_content,0,120,'UTF-8');
echo $content;//120文字を記事から表示
}
}
}
?>" />
<meta property="og:type" content="" />
<meta property="og:url" content="<?php echo (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];?>" />
<meta property="og:image" content="<?php
if(is_home()){
echo get_template_directory_uri().'/2_img/home_img.png';//is_homeでhomeの時のアイキャッチurl
}else if(is_page('memo')){
echo get_template_directory_uri().'/2_img/page_memo.png';//is_page('memo')でカテゴリーmemoのアイキャッチurl
}else if(is_page('portfolio')){
echo get_template_directory_uri().'/2_img/page_portfolio.png';//is_page('portfolio')でカテゴリーportfolioのアイキャッチurl
}else if(is_page('contact')){
echo get_template_directory_uri().'/2_img/page_contact.png';//is_page('contact')でカテゴリーcotntactのアイキャッチurl
}else{
$args = array();
$posts = get_posts( $args );
foreach ( $posts as $post ) : setup_postdata( $post );
$image_id = get_post_thumbnail_id( $post->ID );
$image = wp_get_attachment_image_src( $image_id );
echo $image[0];
endforeach; wp_reset_postdata();
}
?>" />
<meta property="og:site_name" content="<?php echo bloginfo( 'name' );?>" />
<meta property="og:locale" content="ja_JP" />
<meta content="
<?php
if(is_home()){
echo bloginfo('description'); //ブログ説明表示
}else{
if( is_page( 'memo , portfolio , contact' )){
echo category_description();//カテゴリ説明表示
}else{
if(mb_strlen($post->post_content,'UTF-8')>120){
$content = mb_substr($post->post_content,0,120,'UTF-8');
echo $content;//120文字を記事から表示
}
}
}
?>
" name="description">
<title>
<?php if(is_home()){
//homeの時ブログタイトルを表示、ホーム以外は記事タイトルとブログ名を表示
echo bloginfo( 'name' );
}else{
the_title(); echo '/' ; echo bloginfo( 'name' );
}
?>
</title>
<?php wp_head();?>
</head>
<body>
<header class="header">
<div class="menu_button">menu</div>
<div class="logo">
<a href="<?php echo esc_url( home_url() ); ?>"><img src="<?php echo get_template_directory_uri().'/2_img/logo.svg'?>" alt=""></a>
</div>
<nav class="nav1">
<?php
wp_nav_menu(array (
'theme_location' => 'main-menu',
'items_wrap' => '<ul>%3$s</ul>',
'container' => false
) );
?>
<aside class="aside">
<?php if(is_active_sidebar('widget1')) : ?>
<ul id="aside_widget1">
<?php dynamic_sidebar('widget1'); ?>
</ul>
<?php endif; ?>
</aside>
<footer class="footer1">
<p>© mayudesign <?php echo date('Y');?></p>
</footer>
</nav>
<nav class="nav2">
<?php
wp_nav_menu(array (
'theme_location' => 'main-menu',
'items_wrap' => '<ul>%3$s</ul>',
'container' => false
) );
?>
</nav>
</header>
header.php で投稿情報配列が格納されているグローバル変数 $posts が書き換えられています。
$posts は wp_reset_postdata() ではリセットされません。変数名を変更してみてください。
$posts = get_posts( $args );
foreach ( $posts as $post ) : setup_postdata( $post );
↓
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post );
お教えいただいた箇所を直したtころ正常に表示されました。
次回から気を付けたいとおもいます。
ありがとうございます。