Display category name in page title for articles accessed via category blog

Everything to do with Joomla! 3.x templates and templating.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Abatap
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Aug 31, 2017 1:49 pm

Display category name in page title for articles accessed via category blog

Postby Abatap » Thu Aug 31, 2017 2:19 pm

Hello. My question is rather simple. Is there a way to make page title (I'm talking about a <title> tag contents) to also contain the category name the page belongs to but only for those articles which can be accessed through blog category pages? Right now we can only show site name in title before or after the page title which is fine most of the time but can be a problem for SEO / SEF purposes in certain situations.

Right now I have a news section for instance and some of the titles can be a little bit confusing when it comes to what is displayed by search engines or even at the top part of your browser's interface.

Simply put, I want my news articles <title></title> tag to contain something like $title - $category - $site_title instead of just $title - $site_title and I have no idea what template file do I have to override to achieve this because I couldn't find out if there is even a separate template for articles which are children of a blog category template.

Of course, I could do that by overriding the /components/com_content/views/article/tmpl/default.php file, but this would most likely mean that I'd have to filter category names and only modify the title string if the article being displayed belongs to the category of interest which is totally not a generic, reusable solution. So right now I wonder if there is a proper way to do what I want.

User avatar
leolam
Joomla! Master
Joomla! Master
Posts: 18271
Joined: Mon Aug 29, 2005 10:17 am
Location: Netherlands/ UK/ S'pore/Jakarta/ North America
Contact:

Re: Display category name in page title for articles accessed via category blog

Postby leolam » Sun Sep 03, 2017 3:20 pm

No go for this. See https://docs.joomla.org/Help37:Componen ... er_Options for detailed settings

Leo 8)
Celebrating 12-Years of Professional Joomla Support Services
- Joomla Professional Support:https://gws-desk.com -
- Joomla Specialized Hosting Solutions:https://gws-host.com -
- Member Joomla Bug Squad & J-CMS Release Team

Abatap
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Aug 31, 2017 1:49 pm

Re: Display category name in page title for articles accessed via category blog

Postby Abatap » Wed Sep 06, 2017 8:02 am

leolam wrote:No go for this. See https://docs.joomla.org/Help37:Componen ... er_Options for detailed settings

Leo 8)

Sorry but I still can't find a solution using any of these settings.

User avatar
fcoulter
Joomla! Ace
Joomla! Ace
Posts: 1318
Joined: Thu Sep 13, 2007 11:39 am
Location: UK
Contact:

Re: Display category name in page title for articles accessed via category blog

Postby fcoulter » Wed Sep 06, 2017 12:25 pm

Of course, I could do that by overriding the /components/com_content/views/article/tmpl/default.php file, but this would most likely mean that I'd have to filter category names and only modify the title string if the article being displayed belongs to the category of interest which is totally not a generic, reusable solution.


I am pretty sure that this is the only solution that is currently available, there are no Joomla settings that will allow this.

If you don't want to hard-code the category names to filter in the override template (which I agree is something to avoid), you could set this as a site template parameter, you will need to add it to the "params" fields in the template templateDetails.xml file.

Then you can fetch the template parameters in the article template using:

Code: Select all

$templateParams = $app->getTemplate(true)->params;
http://www.spiralscripts.co.uk for Joomla! extensions
http://www.fionacoulter.com/blog my personal website
Security Forum moderator
VEL team member
"Wearing my tin foil hat with pride"

Abatap
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Aug 31, 2017 1:49 pm

Re: Display category name in page title for articles accessed via category blog

Postby Abatap » Wed Sep 06, 2017 12:40 pm

If you don't want to hard-code the category names to filter in the override template (which I agree is something to avoid), you could set this as a template parameter, then you can fetch the template parameters in the article template using:

Code: Select all

$templateParams = $app->getTemplate(true)->params;



Thank you for explanation. I will look into leveraging this template parameters mechanism in my task.


Return to “Templates for Joomla! 3.x”

Who is online

Users browsing this forum: diburto and 11 guests