这是我的标题
<meta property="og:image" content="<?php echo get_the_post_thumbnail($post->ID, 'thumbnail'); ?>" />
这是我页面上的内容,所以这是从
中获取特色图片的地方while (have_posts()) : the_post();
$image_share = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-share' );
$image_post = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'counsel' );
$image_full = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
$comments_count = wp_count_comments( $post->ID );?>
<h3 class="post-info-title"><p class="poster-title"><?php the_title();?></p>
<p class="post-comment"><span class="post-comment-text">Comments</span><span class="post-commment-num"><?php echo $comments_count->approved ;?></span><img class="img-comment" src="<?php echo 'http://edge.beresponsive.net/wp-content/themes/edge-church/images/comment-img.png';?>" /></p>
<p class="share-link-holder share-news"><a class="share-links" onclick="window.open('//player.vimeo.com/v2/video/<?php the_field('vimeo_link');?>/share/facebook', 'Facebook Share', 'width=400, height=300'); return false;" href="javascript:void(0)">Share This</a></p></h3>
<div class="news_holder">
<a class="news_img" href="<?php the_permalink();?>">
</a>
<div class="blur post-cont">
<div class="blurb-text"> <?php the_content(); ?></div>
</div>
</div>
<?php endwhile; ?>>
答案 0 :(得分:0)
使用get queried object
$queried_object = get_queried_object();
echo get_the_post_thumbnail($queried_object->ID, 'thumbnail');
见参考。 on wp codex
答案 1 :(得分:0)
将$ image打印到您的内容=“”;
$page_id = get_queried_object_id();
if ( has_post_thumbnail( $page_id ) ) :
$image_array = wp_get_attachment_image_src( get_post_thumbnail_id( $page_id ), 'optional-size' );
$image = $image_array[0];
else :
$image = get_template_directory_uri() . '/images/default-bg.jpg';
endif;
<meta property="og:image" content="<?php echo $image; ?>" />