【发布时间】:2016-06-22 14:21:37
【问题描述】:
我正在尝试在我的 WordPress 博客中创建一个带有 Google Plus cmets 的框。我的博客在 2016 年 1 月从 http 迁移到 https,所以如果发布日期在迁移日期之前,我想用不同的永久链接调用评论框。
这是原始的 G+ 评论框:
<div class="g-comments"
data-href="<?php the_permalink(); ?>"
data-width="700"
data-first_party_property="BLOGGER"
data-view_type="FILTERED_POSTMOD">
</div>
我使用的是 Studiopress Genesis,G+ 代码放置在原始 WP cmets 与 Genesis Simple Hooks 之前的循环中。这就是我写的,它出现在内容之前。我怎样才能从回声移动到返回?有什么宝贵的帮助吗?
<?php
$permalink = get_permalink();
$now = time();
$compare_time = mktime(0, 0, 0, 1, 1, 2016);
$post_time = get_post_time('U');
$url03 = str_replace('https://', 'http://', $permalink );
if ($post_time < $compare_time) {
echo '<div class="g-comments" data-href="';
echo $url03 . '"';
echo ' data-width="700" ';
echo 'data-first_party_property="BLOGGER" ';
echo 'data-view_type="FILTERED_POSTMOD">';
echo '</div> ';
}
else {
echo '<div class="g-comments" data-href="';
echo the_permalink() . '"';
echo ' data-width="700" ';
echo 'data-first_party_property="BLOGGER" ';
echo 'data-view_type="FILTERED_POSTMOD">';
echo '</div> ';
}
?>
【问题讨论】:
-
那么您将 url 从 http 转换为 https 吗?我认为您的 str_replace 可能是倒退的。
-
现在博客使用 HTTPS,在 2016 年 1 月 1 日之前使用 HTTP。所以我想在 G+ 评论框中调用正确的永久链接 --> $url3
-
您为什么要这样做?您在该日期之前发布的内容现在可以通过 https 访问了吗?
-
我想这样做是因为迁移后博客丢失了所有的 cmets(因为 G+ 在 HTTPS URL 上搜索 cmets)。更改 G+ cmets 调用中的旧帖子 URL,我可以回调所有旧 cmets。该插件有效,但它在任何内容之前执行短代码,这就是问题所在。我红色我应该使用 return 而不是 echo 但我不是专家,我需要一些帮助:)
标签: php wordpress google-plus shortcode genesis