Get News Article Title Displayed in Page Title

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
User avatar
Elijah Lofgren
Power Poster
Power Poster
Posts: 811
Joined: Mon Apr 24, 2006 1:01 am
Location: Deatsville, AL

Get News Article Title Displayed in Page Title

Post by Elijah Lofgren »

To get News Article Title in Page Title like I just got working on this page: http://www.elijahlofgren.com/news/241/56/

Update: The instructions below are now outdated. No source modification is necessary. See this post:  http://forum.cmsmadesimple.org/index.ph ... l#msg58559


1. Open modules/News/action.detail.php
2.Find this line:

Code: Select all

$onerow->title = $row['news_title'];
3.After that line add this code on a new line:

Code: Select all

$this->news_title = $row['news_title'];
4.Log into your CMSMS Admin Panel
5.Go to "Extensions » User Defined Tags"
6.Click the "Add User Defined Tag" link.
7.In the "*Name:" field paste this name (can really be anything as long as no spaces or special chars):

Code: Select all

add_news_title_to_page_title
8.In the "*Code" field paste this:

Code: Select all

global $gCms;
$module =& $gCms->modules['News']['object'];
if (isset($module->news_title))
{
	$text = $module->news_title;
	if (function_exists('str_ireplace'))
	{
		$params['content'] = str_ireplace('<title>', '<title>'.$text. ' - ', $params['content']);
	}
	else
	{
		$params['content'] = eregi_replace('<title>', '<title>'.$text. ' - ', $params['content'] );
	}
}
9.Click the "Submit" button
10.Now go to "Extensions » Events"
11.Click on the "ContentPostRender" link (Description is "Sent before the combined html is sent to the browser") URL will be like: /admin/editevent.php?action=edit&module=Core&event=ContentPostRender
12.From the dropdown  select "add_news_title_to_page_title"
13.Click the "Add" submit button.

Whew, now when a news article is viewed, the page title should have the article title in it.

Hope this helps someone,

Elijah
Last edited by Anonymous on Tue May 08, 2007 9:34 pm, edited 1 time in total.
Note: I don't have time to take on any more projects. I'm quite busy. I may be too busy to reply to emails or messages. Thanks for your understanding. :)
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm
Location: Florida

Re: Get News Article Title Displayed in Page Title

Post by carasmo »

Wowie! :) Thanks!
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm
Location: Florida

Re: Get News Article Title Displayed in Page Title

Post by carasmo »

Works wonderfully! Thanks again. Very, very helpful mod. Easy to understand directions.
User avatar
Elijah Lofgren
Power Poster
Power Poster
Posts: 811
Joined: Mon Apr 24, 2006 1:01 am
Location: Deatsville, AL

Re: Get News Article Title Displayed in Page Title

Post by Elijah Lofgren »

carasmo wrote: Works wonderfully! Thanks again. Very, very helpful mod. Easy to understand directions.
Glad I could help. :)
Note: I don't have time to take on any more projects. I'm quite busy. I may be too busy to reply to emails or messages. Thanks for your understanding. :)
PatDeLux

Re: Get News Article Title Displayed in Page Title

Post by PatDeLux »

Worked fine on first try.Thanks !!!  ;D
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm
Location: Florida

Re: Get News Article Title Displayed in Page Title

Post by carasmo »

How to get the pretty urls to work with news?

news-title-is-the-url

I really, really need it.
tntstudio

Re: Get News Article Title Displayed in Page Title

Post by tntstudio »

Dear Elijah Lofgren,

Thank you this has helped me very much too! I have been having trouble with CMSMS's news plugin for sometime now, and this is one of the solutions I have been looking for.
reidjazz

Re: Get News Article Title Displayed in Page Title

Post by reidjazz »

Elijah,
God has blessed you with many gifts...great coding, generosity...I'm sure there are others.

Many thanks! It's the small things that make the biggest difference most of the tiime!

Todd Reid
brainpoo
Forum Members
Forum Members
Posts: 37
Joined: Wed Jul 05, 2006 1:21 am

Re: Get News Article Title Displayed in Page Title

Post by brainpoo »

You.

Are.

Awesome.


Thank you so much, I've been looking for this solution.  This is totaly great, and thank you so much!
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Get News Article Title Displayed in Page Title

Post by calguy1000 »

Elijah, it'd be cool if you made this a bit more generic.  Such that if you wanted to add stuff to the page title, you could just add things into smarty in either the page template, news, questions, etc, etc. and then use your UDT to handle modifying the title tag.

i.e. this could be added to the questions module detail template:

Code: Select all

{assign var='title_str' value=$record->question}
and then your UDT could use the value from smarty in the str_ireplace, etc.

Code: Select all

global $gCms;
smarty =& $gCms->getSmarty();
$text = $smarty->get_template_vars('title_str');
if (function_exists('str_ireplace'))
{
   ...
}

I'd love to include a UDT like this with the core.
else
{
   ...
}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
Elijah Lofgren
Power Poster
Power Poster
Posts: 811
Joined: Mon Apr 24, 2006 1:01 am
Location: Deatsville, AL

Re: Get News Article Title Displayed in Page Title

Post by Elijah Lofgren »

Turin wrote: This has stopped working in 1.0.5.
You'll probably need to edit the News file again.
Note: I don't have time to take on any more projects. I'm quite busy. I may be too busy to reply to emails or messages. Thanks for your understanding. :)
yankee80
Forum Members
Forum Members
Posts: 34
Joined: Mon Apr 10, 2006 2:45 am

Re: Get News Article Title Displayed in Page Title

Post by yankee80 »

Thanks, this worked great!

Our SEO guy says that NOT displaying unique titles for news-details pages is an SEO catastrophe.

I think there should be a checkbox called "display news title in browser title" or smth. Who should I email this suggestion to?

Kind regards
Eric
pgoneill

Re: Get News Article Title Displayed in Page Title

Post by pgoneill »

Just did this and it's working in 1.0.6.  Thanks for the tip, great work!
moorezilla

Re: Get News Article Title Displayed in Page Title

Post by moorezilla »

yeah... this kicks ass. nice work.

this going to make it into 1.1?
User avatar
Elijah Lofgren
Power Poster
Power Poster
Posts: 811
Joined: Mon Apr 24, 2006 1:01 am
Location: Deatsville, AL

Re: Get News Article Title Displayed in Page Title

Post by Elijah Lofgren »

moorezilla wrote: this going to make it into 1.1?
Modifying the source code is no longer necessary: http://forum.cmsmadesimple.org/index.ph ... l#msg58559 :)
Note: I don't have time to take on any more projects. I'm quite busy. I may be too busy to reply to emails or messages. Thanks for your understanding. :)
Post Reply

Return to “Tips and Tricks”