Open nigelcopley opened 8 years ago
How exactly would this work?
Add a field into article for SEO Title
This then overrides page title when article is rendered as page. I can share the code we used to extend the moduleArticle.php with you if you want.
What if there are multiple articles?
I think he means for the detail page of an article.
I guess he means if you use /…/article/alias.html url where one article is rendered.
As fritz and andreas say it's only applicable when the article is rendered
dca/tl_article.php
<?php
/**
* Extend default palette
*/
$GLOBALS['TL_DCA']['tl_article']['palettes']['default'] = str_replace
(
'keywords',
'keywords,seo_title',
$GLOBALS['TL_DCA']['tl_article']['palettes']['default']
);
/**
* Add fields
*/
$GLOBALS['TL_DCA']['tl_article']['fields']['seo_title'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_article']['seo_title'],
'exclude' => true,
'inputType' => 'text',
'eval' => array('tl_class'=>'clr long'),
'sql' => "text NULL"
);
/modules/moduleArticle.php
<?php
namespace MyNameSpace;
class ModuleArticle extends \Contao\ModuleArticle
{
/**
* Generate module
*/
protected function compile()
{
parent::compile();
/** @var \PageModel $objPage */
global $objPage;
// Get section and article alias
list($strSection, $strArticle) = explode(':', \Input::get('articles'));
if ($strArticle === null)
{
$strArticle = $strSection;
}
if (!$this->blnNoMarkup && $strArticle != '' && ($strArticle == $this->id || $strArticle == $this->alias) && $this->title != '')
{
if ($this->seo_title) {
$objPage->pageTitle = $this->seo_title;
} else {
$objPage->pageTitle = strip_tags(strip_insert_tags($this->title));
}
}
}
}
langauges/en/tl_article.php
<?php
/**
* Fields
*/
$GLOBALS['TL_LANG']['tl_article']['seo_title'] = array
(
'SEO Title',
'Here you can enter a custom title which will overwrite the page title'
);
Related tickets: #6582 #7830
This is useful when you have a page that contains multiple articles with read more as it gives you more flexibility and control over your SEO params. We've done it by extending the DCA (tl_article.php) and the Module (ModuleArticle.php) but would be useful for others as part of the core