【问题标题】:How to put meta tags for each news post PHP (no wordpress)如何为每篇新闻文章 PHP 放置元标记(无 wordpress)
【发布时间】:2015-01-22 11:38:46
【问题描述】:

您好,我不寻找 wordpress 插件或其他东西。这是我的 php 页面。

<html>
<head>
blablablalba
<?php to_head(); ?>
</head>
<body>
bla bla bla
<?php 
if(isset($_GET['post_id'])) {
    $select=mysqli_query($con,"select....");
    while($data=mysqli_fetch_array($select)) {
         echo "bla bla bla";
         to_head("<title>asd</title><meta itemprop="name" content="Najnovije informacije iz sveta hostinga">...");
    } 
}
?>
bla bla bla
</body>
</html>

我需要为每个新闻帖子设置不同的元标记并放入头部。我该怎么做?

【问题讨论】:

标签: php function tags meta head


【解决方案1】:

你需要填充变量,然后将变量回显到 html...par 示例

<?php 
if(isset($_GET['post_id'])) {
$head = "bla bla";
$body = "bla bla";
    $select=mysqli_query($con,"select....");
    while($data=mysqli_fetch_array($select)) {
         $body .= "bla bla bla";
         $head .= "<title>asd</title><meta itemprop="name" content="Najnovije informacije iz sveta hostinga">...";
    } 
}
?>
<html>
<head>
<?= $head ?>
</head>
<body>
<?= $body ?>
</body>
</html>

【讨论】:

  • 我在 news.php 中有 header.php 和 news.php 我包括 header.php 而在 news.php 我需要为帖子设置不同的变量,所以 之前的 mysqli_query 不起作用对我来说
  • @user1721620 据我所知,php 中无法更改文档前面的标签。
  • 是的,cms php-fusion 中有带有 add_to_head() 的函数;但我不知道,也找不到工作原理。
【解决方案2】:
<?php
ob_start();
include("header.php");
//some mysqli_query with $seo='tags...';
//this is body of document
//footer of document footer.php start
?></body>
</html>
<?php
$buffer=ob_get_contents();
ob_end_clean();
$buffer=str_replace("#</head>#",$seo."</head>",$buffer);
echo $buffer;
//end of footer.php
?>

这就是我在 php 中寻找的东西,以便将您的元标记从查询设置为头部 当然,这可以花费,但想法是这样的。 tnx evryone 的回复和评论..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多