元标记中的 PHP 不起作用?
我对编程很陌生,所以请耐心等待...我的网站基于 Wordpress,所以我有一个索引页,上面写着 和
...我的 header.php 包含您所期望的内容,而 pagecontent.php 实际上是一个非常复杂的页面,它从数据库中获取多个变量(例如,
$result->properties ->名称
)。我开始集成 Facebook Connect 插件(如按钮和评论框),当我将 PHP 放入 中的
标记时,Facebook 无法识别
$result->properties->name
的值...如果我的 php 文件都相同,相关代码将如下所示:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:og="http://ogp.me/ns#"
xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
[REMOVED THE DIV TAG HERE]<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
<?php
echo '<meta property="og:title" content="' . $result->properties->name . ' on Name of Site"/>';
echo '<meta property="og:type" content="movie"/>';
echo '<meta property="og:image" content="http://ia.media-imdb.com/rock.jpg"/>';
echo '<meta property="og:site_name" content="Name of Site"/>';
echo '<meta property="fb:admins" content="698461078"/>';
echo '<meta property="og:description" content="' . $result->properties->description . '"/>';
?>
</head>
<body>
[MOVED DIV TAG DOWN HERE]<div id="fb-root"></div><fb:like href="http://www.sitename.net/?sg=' . $sg_id . '&task=0" send="false" layout="button_count" width="450" show_faces="true" action="recommend" font="tahoma"></fb:like>
</body>
I试图尽可能完整为了避免猜测:P 此代码为喜欢的页面提供标题“在网站名称上”,而不是“在网站名称上的电影名称”。为什么它无法获取变量?我可以做些什么来修改 pagecontent.php 中的元标记吗?请不要害怕说出显而易见的事情!非常感谢;)
I'm very new to programming so bear with me... My site is based on Wordpress, so I have an index page that says <?php get_header(); ?>
and <?php include('pagecontent.php'); ?>
... My header.php contains what you'd expect and pagecontent.php is actually a pretty complex page that grabs several variables from a database (for instance, $result->properties->name
). I'm starting to integrate Facebook Connect plugins (the like button and comment box), and when I put PHP in my <meta>
tags in the <head>
, Facebook doesn't recognize the value of $result->properties->name
... IF my php files were all the same, the relevant code would look like this:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:og="http://ogp.me/ns#"
xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
[REMOVED THE DIV TAG HERE]<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
<?php
echo '<meta property="og:title" content="' . $result->properties->name . ' on Name of Site"/>';
echo '<meta property="og:type" content="movie"/>';
echo '<meta property="og:image" content="http://ia.media-imdb.com/rock.jpg"/>';
echo '<meta property="og:site_name" content="Name of Site"/>';
echo '<meta property="fb:admins" content="698461078"/>';
echo '<meta property="og:description" content="' . $result->properties->description . '"/>';
?>
</head>
<body>
[MOVED DIV TAG DOWN HERE]<div id="fb-root"></div><fb:like href="http://www.sitename.net/?sg=' . $sg_id . '&task=0" send="false" layout="button_count" width="450" show_faces="true" action="recommend" font="tahoma"></fb:like>
</body>
I tried to be as complete as possible to avoid guesswork :P This code gives liked pages the title " on Name of Site" instead of "Name of Movie on Name of Site". Why isn't it able to grab the variable? Is there something I can do to modify the meta tags from within pagecontent.php? Please don't be afraid to state the obvious things! Many thanks ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于您上面的评论,您说:
将获取值的代码移至
meta
标记之前。On your comments above you say:
Move the code that grabs the value before the
meta
tags.