如何为每个新闻帖子放置元标记PHP(没有wordpress)


How to put meta tags for each news post PHP (no wordpress)

你好,我不找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>

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

您需要填充变量,然后将变量回显到 html...标准杆示例

<?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>
<?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的回复和评论..