我正在寻找一种方法来显示在Facebook上分享时的帖子摘录,这是我的代码,但它确实显示帖子的_exceprt。 ..
<a <a target="_blank" href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&t= <?php the_excerpt(); ?><?php the_title(); ?>"<i class="fa fa-facebook"></i></a>
如果可以提供帮助,这是包含所有代码的部分(它是一个网格系统,&#34;网格&#34;每个框都有不同的内容)
<div data-ratio="1" class="grid__item grid__item_inline one-half cell tabbed" style="background-color: #ccffff" >
<a href="LINK_TO_PRESS_POST"><h1>Press room</h1></a>
<?php
$query = new WP_Query( array( 'post_type' => 'coverage', 'posts_per_page' => 1 ) );
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
?>
<time class="timestamp"><?php the_date(); ?></time>
<h2 class="h4"><?php the_title(); ?></h2>
<div class="palm--hidden"><?php the_excerpt(); ?><p></p></div>
<a href="<?php the_permalink(); ?>" class="palm--hidden">Read More</a>
<div class="social-icons-2">
<ul class="hl">
<li>Share:</li>
<li><a <a target="_blank" href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&t= <?php the_excerpt(); ?><?php the_title(); ?>"<i class="fa fa-facebook"></i></a></li>
<li><a href="http://twitter.com/home?status= Take a look<?php the_title(); ?> <?php the_permalink(); ?>" class="icon"><i class="fa fa-twitter"></i></a></li>
<li><a href="" class="icon"><i class="fa fa-pinterest"></i></a></li>
</ul>
</div>
<?php
endwhile; endif;
?>
</div>
</article>
</div>
与此facebook分享有关的另一个问题,目前它正在分享网站的标识。 。是否有可能展示帖子的图片附件?
非常感谢您提前所有的时间
编辑:我把这个页面的所有代码放在这里,以防它脚跟。 ..<?php get_header(); ?>
<div id="slider-header">
<div class="container">
<div class="row">
<div class="col-sm-4 slider-header-left">
WHAT WE DO
</div>
<div class="col-sm-8 slider-header-right">
texttt
</div>
</div>
</div>
</div>
<div id="main" class="site-main" role="main">
<div id="home-slider">
<div class="container">
<div class="row home-content-slider">
<?php
$services = get_page_by_path('services');
if($services) $parent = $services->ID;
$the_query = new WP_Query( array( 'post_type' => 'page', 'post_per_page' => 5, 'post_parent' => $parent, 'order' => 'ASC' ) );
$service_titles = array();
$service_images = array();
if ( $the_query->have_posts() ) {
$i = 1;
while ( $the_query->have_posts() ) {
$the_query->the_post();
$service_titles[] = '<li id="nav-fragment-'. $i .'" class=""><a href="#fragment-'. $i .'" ><span>'. get_the_title() .'</span></a></li>';
$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
$image = wp_get_attachment_image_src( $post_thumbnail_id, 'full' );
$service_images[] = '<div id="fragment-'. $i .'" class="ui-tabs-panel ui-tabs-hide"><img src="'. $image[0] .'" title="" /><div class="overlay-description">'. get_field('slider_text') .'</div></div>';
$i++;
}
}
wp_reset_postdata();
?>
<div class="col-sm-4 home-slider-left">
<div class="row">
<ul>
<?php echo implode( "\n", $service_titles ); ?>
</ul>
</div>
</div>
<div class="col-sm-8 home-slider-right">
<div class="row">
<?php echo implode( "\n", $service_images ); ?>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div id="grid_container">
<div class="row">
<div class="col-sm-6 news-post" style="background-color: #ccfff" data-key="newsItem">
<article class="grid row">
<div data-ratio="1" class="grid__item grid__item_inline one-half">
<?php
echo '<div class="flexslider">';
echo '<ul class="slides">';
$query = new WP_Query( array( 'post_type' => 'coverage', 'posts_per_page' => 9 ) );
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
$image = wp_get_attachment_image_src( $post_thumbnail_id, 'homepage-thumb' );
if($image) echo '<li><a href="'. get_permalink() .'"><img class="img-responsive" src="'. $image[0] .'" alt="" /></a></li>';
endwhile; endif;
echo '</ul>';
echo '</div>';
?>
<?php wp_reset_postdata(); ?>
</div>
<div data-ratio="1" class="grid__item grid__item_inline one-half cell tabbed" style="background-color: #ccffff" >
<a href="http://LINKK_TO.com/?post_type=coverage"><h1>Press room</h1></a>
<?php
$query = new WP_Query( array( 'post_type' => 'coverage', 'posts_per_page' => 1 ) );
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
?>
<time class="timestamp"><?php the_date(); ?></time>
<h2 class="h4"><?php the_title(); ?></h2>
<div class="palm--hidden"><?php the_excerpt(); ?><p></p></div>
<a href="<?php the_permalink(); ?>" class="palm--hidden">Read More</a>
<div class="social-icons-2">
<ul class="hl">
<li>Share:</li>
<li><a <a target="_blank" href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&t= <?php the_excerpt(); ?><?php the_title(); ?>"<i class="fa fa-facebook"></i></a></li>
<li><a href="http://twitter.com/home?status= Take a look<?php the_title(); ?> <?php the_permalink(); ?>" class="icon"><i class="fa fa-twitter"></i></a></li>
<li><a href="" class="icon"><i class="fa fa-pinterest"></i></a></li>
</ul>
</div>
<?php
endwhile; endif;
?>
</div>
</article>
</div>
<div class="col-sm-6 news-post" style="background-color: #ffcccc" data-key="newsItem">
<article class="grid row">
<?php
$query = new WP_Query( array( 'post_type' => 'news', 'posts_per_page' => 1 ) );
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
?>
<div data-ratio="1" class="grid__item grid__item_inline one-half">
<figure data-ratio="1">
<?php
$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
$image = wp_get_attachment_image_src( $post_thumbnail_id, 'homepage-thumb' );
?>
<a href="<?php echo get_permalink(); ?>"><img width="640" height="640" class="img-responsive" src="<?php echo $image[0]; ?>" alt="" /></a>
</figure>
</div>
<div data-ratio="1" class="grid__item grid__item_inline one-half cell tabbed" style="background-color: #ffcccc" >
<a href="<?php the_permalink(); ?>"><h1>NEWS</h1></a>
<time class="timestamp"><?php the_date(); ?></time>
<h2 class="h4"><?php the_title(); ?></h2>
<div class="palm--hidden"><p><?php the_excerpt(); ?></p></div>
<a href="<?php the_permalink(); ?>" class="palm--hidden">Read More</a>
<div class="social-icons-2">
<ul class="hl">
<li>Share:</li>
<li><a href="SM1" class="icon"><i class="fa fa-facebook"></i></a></li>
<li><a href="sm2" class="icon"><i class="fa fa-twitter"></i></a></li>
<li><a href="sm3" class="icon"><i class="fa fa-pinterest"></i></a></li>
</ul>
</div>
</div>
<?php
endwhile; endif;
?>
</article>
</div>
<div class="col-sm-6 news-post" style="background-color: #ffffff" data-key="newsItem">
<article class="grid row">
<div data-ratio="1" class="grid__item one-half">
<figure data-ratio="1">
<!-- SnapWidget -->
<!-- SnapWidget -->
<!-- SnapWidget -->
<iframe src="http://snapwidget.com/sc/?u=aW5fc3BhY2VzfGlufDI4MHwzfDN8fG5vfDV8bm9uZXx8eWVzfG5v&ve=020914" title="Instagram Widget" class="snapwidget-widget" allowTransparency="true" frameborder="0" scrolling="no" style="border:none; overflow:hidden; width:295px; height:295px"></iframe>
</figure>
</div>
<div data-ratio="1" class="grid__item grid__item_inline one-half cell tabbed twitter-widget" style="background-color: #ffffff" >
<a class="twitter-timeline" data-dnt="true" href="sm2" data-widget-id="501148708545638400">Tweets by @In__Spaces</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>
</article>
</div>
<div class="post-1410 post type-post status-publish format-standard has-post-thumbnail hentry category-news col-sm-6 news-post" style="background-color: #ffffcc" data-key="newsItem">
<article class="grid row">
<?php
$query = new WP_Query( array( 'post_type' => 'event', 'posts_per_page' => 1 ) );
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
?>
<div data-ratio="1" class="grid__item grid__item_inline one-half">
<figure data-ratio="1">
<?php
$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
$image = wp_get_attachment_image_src( $post_thumbnail_id, 'homepage-thumb' );
?>
<a href="<?php echo get_permalink(); ?>"><img width="640" height="640" class="img-responsive" src="<?php echo $image[0]; ?>" alt="" /></a>
</figure>
</div>
<div data-ratio="1" class="grid__item grid__item_inline one-half cell tabbed" style="background-color: #ffffcc" >
<a href="<?php the_permalink(); ?>"><h1>EVENTS</h1></a>
<time class="timestamp">August 22, 2014</time>
<h2 class="h4"><?php the_title(); ?></h2>
<div class="palm--hidden"><p><?php the_excerpt(); ?></p></div>
<a href="<?php the_permalink(); ?>" class="palm--hidden">Read More</a>
<div class="social-icons-2">
<ul class="hl">
<li>Share:</li>
<li><a href="" class="icon"><i class="fa fa-facebook"></i></a></li>
<li><a href="" class="icon"><i class="fa fa-twitter"></i></a></li>
<li><a href="" class="icon"><i class="fa fa-pinterest"></i></a></li>
</ul>
</div>
</div>
<?php
endwhile; endif;
?>
</article>
</div>
<div class="big-link">
</div>
</div>
</div>
</div>
</div><!-- #main -->
<?php get_footer(); ?>
答案 0 :(得分:0)
您需要在页面的<head>
部分使用Open Graph Tags。
以下是一个例子:
<meta property="og:title" content="<?=the_title();?>" />
<meta property="og:description" content="<?=the_excerpt();?>" />
<meta property="og:type" content="blog" />
<meta property="og:url" content="<?=the_permalink();?>" />
<meta property="og:site_name" content="YOUR_SITE_NAME" />