【发布时间】:2018-01-05 05:35:19
【问题描述】:
基于 Joomla 的网站。我有很多页面,其中h1 标头被提及为产品详细信息,并通过 PHP 根据产品详细信息显示。有 2 个文件:default.php 和 view.html.php。
default.php:
<h1>Used <?php echo $this->CatName; ?> <?php echo $this->prodDet->prod_name;?> Toy for Sale </h1>
这会正确显示h1 标记。我想生成页面的元标题并使用在 view.html.php 中生成的 h1 输出。这一行定义了页面的标题:
$this->document->setTitle($title);
这一行定义了标题h1:
"{$this->item->heading}";
完整代码:
protected function _prepareDocument()
{
$app = JFactory::getApplication();
$menus = $app->getMenu();
$title = null;
// Because the application sets a default page title,
// We need to get it from the menu item itself
$menu = $menus->getActive();
if ($menu)
{
$this->params->def('page_heading', $this->params->get('page_title', $menu->title));
}
else
{
$this->params->def('page_heading', JText::_('COM_USEDCAR_DEFAULT_PAGE_TITLE'));
}
$title = $this->params->get('page_title', '');
if (empty($title))
{
$title = $app->get('sitename');
}
elseif ($app->get('sitename_pagetitles', 0) == 1)
{
$title = JText::sprintf('JPAGETITLE', $app->get('sitename'), $title);
}
elseif ($app->get('sitename_pagetitles', 0) == 2)
{
$title = JText::sprintf('JPAGETITLE', $title, $app->get('sitename'));
}
$title = "{$this->item->heading}";
$this->document->setTitle($title);
if ($this->params->get('menu-meta_description'))
{
$this->document->setDescription($this->params->get('menu-meta_description'));
}
if ($this->params->get('menu-meta_keywords'))
{
$this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
}
if ($this->params->get('robots'))
{
$this->document->setMetadata('robots', $this->params->get('robots'));
}
}
标题标签中的输出是heading。如何把这个h1标签输出而不是$title?
【问题讨论】:
-
在线上方:
$this->document->setTitle($title);您可以将$title重新定义为您想要的任何内容。只要确保您没有破坏该函数的一般逻辑即可。 -
@Difster - 查看已更新,未显示正确的标题标签,任何帮助
-
这是 joomla 吗?如果是,您可以在菜单选项中设置页面标题
-
是的,这是 joomla,但它是一个自定义组件,并且菜单中没有这样的页面标题,因为此菜单中有 100 多个产品页面,并且需要这些页面的页面标题类似于 h1 标签在页面上创建。
-
有谁能帮忙