获取URL,标题和摘录的个人帖子内的模板- wordpress
Getting URL,Title and excerpt of Individual post inside template-Wordpress
我尝试在索引模板内添加一个社交共享脚本,当我点击共享burron时,我想获得个人帖子的URL。我在javascript中定义了这个结构。
<a class="fb-share" href="javascript:void(0)" onclick="facebook('Link of the post', 'Title of the post','Excerpt of the post','Thumbnail of featured image');"></a>
我尝试使用链接的帖子http://www.dreamstopixels.com/%postname%和失败。我需要一些建议,谢谢。
您需要在索引模板的The Loop中添加一些代码来获取数据并生成链接。在the_post();
被调用后,将以下内容放入while
循环中:
<?php
$url = get_permalink();
$title = get_the_title();
$excerpt = get_the_excerpt();
$image = get_the_post_thumbnail(get_the_ID(), 'thumbnail');
?>
这设置了您需要的所有数据,然后您只需构建调用脚本并将数据传递给facebook的锚标记:(仍在循环中)
<?php
$fbonclick = "facebook('".$link."','".$title."','".$excerpt."','".$image."');";
?>
然后创建链接:
<a class="fb-share" href="javascript:void(0)" onclick="<?php echo $fbonclick; ?>"></a>
老实说,我不知道为什么你需要这样做,虽然有上千个社交分享插件。使用AddThis之类的
尝试使用这些函数:
http://codex.wordpress.org/Function_Reference/get_permalink
http://codex.wordpress.org/Function_Reference/get_the_title
http://codex.wordpress.org/Function_Reference/get_the_excerpt
WORDPRESS CODEX上有很多文档。在开发wordpress模板时,您应该始终保持打开状态。
拉尔。
相关文章:
- 如何使用URL筛选wordpress自定义帖子类型
- 嵌入iframe URL以在wordpress中包含当前用户id
- 如何在wordpress插件中获取jquery中的img url和文件url
- iFrame URL参数到Wordpress中的
- 如何在WordPress中即时重定向URL
- 在WordPress中,获取样式表中的网站URL
- Wordpress ajax url ... not send
- 如何在WordPress中将查询字符串/参数添加到url
- 在Wordpress模板中使用Javascript或Jquery添加基于URL的CSS类
- 使用jQuery(在wordpress上)粗体链接到父URL
- Wordpress在脚本页面的url中添加一个数字
- 通过wordpress中的URL从下拉列表中选择选项
- 从wordpress视频URL字段(在JW播放器脚本中)获得Javascript中的值
- 通过更改链接中的url链接到Wordpress移动站点的确切页面
- 获取URL,标题和摘录的个人帖子内的模板- wordpress
- 在Wordpress中查找和替换Iframe URL
- 在Wordpress中基于Url隐藏菜单Div类
- 这是正确的方法& &;或者,amp;在Wordpress url
- AJAX url数据发送与友好的url's在Wordpress
- 资产URL中的双斜杠-WordPress中的404错误