duanqinjiao5244 2011-06-14 20:36
浏览 19
已采纳

元标记中的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 ;)

  • 写回答

1条回答 默认 最新

  • douzhang1955 2011-06-14 21:14
    关注

    On your comments above you say:

    $result is being populated by an S3 database - the code that grabs the value is about 20 lines before the tag. So it's effectively after the meta tags and before the like button

    Move the code that grabs the value before the meta tags.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?