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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度