joomla 3.x-如何在标题中包含“ metadescription”和“ title”而不使用<jdoc:include type =“ head” />

Dio*_*nik 3 php joomla

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

通过搜索,我找到了有关该主题的旧帖子,并且在网络上有些人正在寻找相同的东西。在Joomla中手动控制<head>标记

我想知道是否有可能将我的index.php模板文件添加到可以获取Joomla出版物的“ metadescription”和“ title”的PHP代码中。像这样:

  <?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> 
Run Code Online (Sandbox Code Playgroud)

Dio*_*nik 5

很好,虽然我可以找到我想要的代码,也许它可以帮助其他人,但是它对我有用...在我添加的模板的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> 
Run Code Online (Sandbox Code Playgroud)