php - joomla 3.x - 如何在不使用 <jdoc :include type "metadescription"/> 的情况下在 header 中包含 "title"和 ="head"

标签 php joomla

我试图更好地控制我的 Joomla 网站的标题;对于某些页面,标题中不需要很多内容。我决定制作一个不使用 <jdoc:include type="head" /> 的模板,因为它加载了很多我不需要的东西。

搜索时,我发现了这篇关于该主题的旧帖子,并且在网络上有人在寻找相同的东西。 Manually control <head> markup in Joomla

我想知道是否可以添加到我的 index.php将模板文件转换为 PHP 代码,可以获取 Joomla 出版物的“元描述”和“标题”。像这样:

  <?php defined( '_JEXEC' ) or die; ?>
    <!doctype html>
    <html lang="<?php echo $this->language; ?>"> 
    <head> 
    <meta name="viewport" content="width=device-width />
    <meta name="description" content="<?php echo **code metadescription** ?>" />
    <title><?php echo **code to get title** ?></title>
    </head>
    <body> 
    <jdoc:include type="component" />  
    </body>
    </html> 

最佳答案

很好,过了一会儿我找到了我正在寻找的代码,也许它可以帮助其他人,它对我有用......在我添加的模板的 index.php 文件中:

<?php defined( '_JEXEC' ) or die;
$doc =JFactory::getDocument(); 
$meta_description = $doc->getMetaData("description"); 
$title = $doc->getTitle();
?>
<!doctype html>
<html lang="<?php echo $this->language; ?>">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" /> 
<meta name="description" content="<?php echo "$meta_description"; ?>" />
<title><?php echo "$title" ?></title> 
</head>
<body> <jdoc:include type="component" />  </body>
</html> 

关于php - joomla 3.x - 如何在不使用 <jdoc :include type "metadescription"/> 的情况下在 header 中包含 "title"和 ="head",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30858171/

相关文章:

php - strftime() : bool(false) not showing nothing

php - 用于购物的谷歌内容 API

html - 无法访问 Joomla HTML 或 CSS 代码

javascript - Laravel 显示 JS 确认对话框与另一个 JS 函数内联

php - Yii2 - 如何通过数据透视表过滤相关模型

postgresql - 在 Joomla 中连接到 PGSQL 数据库时出错

Joomla Menu-别名不止一次

php - 通过事件的父菜单项获取主体类

php - 在 WordPress 中使用复选框过滤输出

view - 如何在模态窗口中放置 Joomla 2.5 后端 View