获取URL,标题和摘录的个人帖子内的模板- wordpress

Getting URL,Title and excerpt of Individual post inside template-Wordpress

本文关键字:wordpress URL 标题 获取      更新时间:2023-09-26

我尝试在索引模板内添加一个社交共享脚本,当我点击共享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模板时,您应该始终保持打开状态。

拉尔