WordPress的 - 显示facebook上的帖子的分享
问题描述:
我正在寻找一种方式来显示在facebook上分享时的帖子摘录,这里是我的代码,但它显示帖子的the_exceprt。 ..WordPress的 - 显示facebook上的帖子的分享
<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>
如果它可以帮助,这是与所有代码(这是一个网格系统,“网格”的每个盒子都有不同的内容)的部分与有关
<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分享,现在它分享网站的标志。 。任何可能显示insterad图片附加的帖子?
非常感谢你对你所有的时间提前
编辑:我把这里的页面的所有代码,它heelps情况。 ...
<?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(); ?>
答
您需要在页面的<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" />
嗯,如果我ADDD这在我的header.php它dsiplay我所有德社交媒体图标,犯规显示摘录依旧。 ..我不需要官方图标,因为我需要使用一些个人图标进行分享。如果你有任何解决方案?谢谢:) – tibewww 2014-10-10 14:35:33
我已经添加了页面的所有代码以防止它 – tibewww 2014-10-10 14:38:20
我没有说把它放在'header.php'文件中,我说过HTML文档的头部,无论它包含什么。我认为你需要考虑阅读Wordpress Codex。 – adamdehaven 2014-10-10 18:03:49