ワードプレス
ショートコードでpost_idを取得
固定ページでショートコードでサイズを指定した画像が読み込めませんでした。
ショートコードではpost_idが空になっていたのが原因でした。
<?php if(is_mobile()){
query_posts( 'category_name=house,shop,office,other&posts_per_page=4');
}else{
query_posts( 'category_name=house,shop,office,other&posts_per_page=8');
} ?>
<?php if(have_posts()): ?>
<?php while(have_posts($post->ID)): the_post(); ?>
<?php
$post_id = get_the_ID();
$category = get_the_category();
$cat_name = $category[0]->cat_name;
$cat_slug = $category[0]->category_nicename;
?>
<li>
<span class="proCat">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>works/<?php echo $cat_slug; ?>"><?php echo $cat_name; ?></a>
</span>
<a href="<?php the_permalink(); ?>">
<figure>
<?php $image_cons01 = wp_get_attachment_image_src( get_post_meta($post_id,'works-pic-main', true),'size1' ); ?>
<?php //$image_cons01 = wp_get_attachment_image_src( get_post_meta(get_the_ID();,'works-pic-main', true),'size1' ); ?>
<img src="<?php echo $image_cons01[0]; ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?>" >
</figure>
<h3><?php the_title(); ?></h3>
</a>
</li>
<?php endwhile; ?>
</ul>
<div class="detailLink"><a href="<?php echo esc_url( home_url( '/' ) ); ?>works">施工事例一覧</a></div>
<?php else : ?>
<div id="entryNon">
現在、施工実績の登録は御座いません。
</div>
<?php endif; wp_reset_query(); ?>
