[SOLVED] How can I display News title in Page title ?

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
User avatar
fredt
Forum Members
Forum Members
Posts: 144
Joined: Mon Jun 27, 2005 10:36 am

[SOLVED] How can I display News title in Page title ?

Post by fredt »

My general template currently has the standard thing :
ACME Company - {title}

So when I display a News with title "New Office in New York" on page "Company News" , I only get "ACME Company - Company News" in page title.

I'd like to get "ACME Company - Company News - New Office in New York" in title - so Google would index it better...

(using php4 and CMSMS 0.11.2)

How can I achieve this ?
Last edited by fredt on Mon May 19, 2008 5:45 pm, edited 1 time in total.
User avatar
fredt
Forum Members
Forum Members
Posts: 144
Joined: Mon Jun 27, 2005 10:36 am

Re: How can I display News title in Page title ?

Post by fredt »

Please... Can't this been achieved ???

Can you give me a starting point ?

(Desperate) Fred
nils73
Power Poster
Power Poster
Posts: 520
Joined: Wed Sep 08, 2004 3:32 pm

Re: How can I display News title in Page title ?

Post by nils73 »

I believe that there is no option right now which would do what you want. I was sure this would work somehow (creating a detailpage and a single news template with special head-tags) but it didn't work as expected since I would need two modules-tags for News on one page which does not work with my install (0.12.1) ... maybe someone else has a good idea on how to grab parts of the {content} and push it to {title} if needed. Maybe this should be a feature request for an attribute in title.

Regards,
Nils
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: How can I display News title in Page title ?

Post by Ted »

I think the only real "clean" way to do this is the make a module API callback.

Obviously, you could hack the title tag/plugin apat and stuff it in there.  However, I usually look for a cleaner solution...

The title is sitting in
$gCms->variables['pageinfo']->content_title.  Now, the problem is that you need to get that changed out before the {title} tag is rendered.  This, of course, will most likely happen BEFORE the {content} tag that you're going to spit the news out in is rendered.  So, you're going to have to get in there earlier in the rendering loop.

TemplatePostCompile is probably your best bet, though it's not tested.  I would add that to the news module (or better yet, make your own one-off module that does this one thing) and then do a bit of quick url parsing to figure out the news article.  Then query, overwrite the existing title, and done.

A little less hacky, plus you get under the CMSMS hood a little more.  :)

I'll see what I can do about getting a callback to use in the future to make it about 10,000x easier.
User avatar
fredt
Forum Members
Forum Members
Posts: 144
Joined: Mon Jun 27, 2005 10:36 am

Re: How can I display News title in Page title ?

Post by fredt »

Pheewwww.... THAT's a start point. I'll have no excuse not trying.

So... let's go under the hood  :).    I'll post an update later (success or ...success)  ;D.
User avatar
fredt
Forum Members
Forum Members
Posts: 144
Joined: Mon Jun 27, 2005 10:36 am

Re: How can I display News title in Page title ?

Post by fredt »

OK, I'm going crazy. I thought I had found a solution, but there must be something wrong somewhere.  :(

If I add this to News.module.php, in Class New :

Code: Select all

function TemplatePostCompile()
	{
		global $gCms;
		$gCms->variables['pageinfo']->content_title = "MyTitle";
	}
1. It works ONLY IF $config['debug'] = true; in config.php (I have "MyTitle" on browser title);

2. And it applies to ALL pages - not only those with News
    >:( Arggghhh, I see why while writing this: I display News in left margins on all pages.
    OK, forget this Point 2.


In the complete solution:

I first get the News title in TemplatePostCompile function and write it in a global PageInfo variable (no url parsing!) :

Code: Select all

		//get the current Article ID from smarty
		$local_smarty_id = $gCms->smarty->id;
		$local_articleid = $gCms->smarty->params[$local_smarty_id . "articleid"];
		
		if ($local_articleid <> "") { 
			//Query the db and get the title
			$myquery = "SELECT mn.*, mnc.news_category_name FROM ".cms_db_prefix()."module_news mn LEFT OUTER JOIN ".cms_db_prefix()."module_news_categories mnc ON mnc.news_category_id = mn.news_category_id WHERE status = 'published' AND news_id = ?";
			$mydb = $this->cms->db;
			$mydbresult = $mydb->Execute($myquery, $local_articleid);
			
			while ($myrow = $mydbresult->FetchRow())
			{
				$mytitle = $myrow['news_title'];
			}
			//Add Current News Title to smarty vars as :  content_title_news - will be displayed by the new "Title_News" tag (extending Title)
			$gCms->variables['pageinfo']->content_title_news = $mytitle;
			}
I've copied function.title.php ({title} tag) to function.title_news.php, which displays $pageinfo->content_title_news - so now I have a title_news tag.

Then I display my News page through a "My_News" template, with

Code: Select all

<title>General title - {title} : {title_news}</title>
... but, alas, alas, i only works if Debug is True.

Will you help me ?

(Oops - almost forgot : running 0.11.2 under Apache 1.3.34 and php 4.4.2)
User avatar
petert
Power Poster
Power Poster
Posts: 282
Joined: Wed Feb 09, 2005 9:30 pm

Re: How can I display News title in Page title ?

Post by petert »

fredt wrote: 1. It works ONLY IF $config['debug'] = true; in config.php (I have "MyTitle" on browser title);
Thta's because debugging mode cancels the caching of pages. You have to use some smarty magic to get around that one (insert maybe?)
Mambo sucks, that's why I am here.
Now they call it Joomla, but it still sucks!

CMSMS rules!
User avatar
fredt
Forum Members
Forum Members
Posts: 144
Joined: Mon Jun 27, 2005 10:36 am

Re: How can I display News title in Page title ?

Post by fredt »

Thanks for your prompt answer.

I've been looking in code and forum - couldn't find a way to achieve this. Can you please point me out to an example ?

(Pages displaying News are  NOT checked as Cached).

... I now have the feeling function TemplatePostCompile() should be told which template to process... Any clue on this ??
rbeemsterboer

Re: How can I display News title in Page title ?

Post by rbeemsterboer »

This option would be nice!

Very Nice!

i've been checking google all day and trying to check if they index CMSMS websites in a good way.
it seems that it doenst want to index the news pages and that a pitty!!

the current raking of the website im building totally relies on tha (34 pages of results)
If i can put the news title in the topic, that would help certainly

i keep my fingers crossed for the full release of cmsms!! ;)

Regards,
Rick - Amsterdam
webporter
New Member
New Member
Posts: 4
Joined: Sun Aug 19, 2007 6:21 am

Re: How can I display News title in Page title ?

Post by webporter »

This patch may help you (though didn't help me):

* News Module Patch [#1325] Adds Article Title to Page Title

Not sure if my problem is related to server settings, or if this patch just doesn't work in Black Rock...
User avatar
fredt
Forum Members
Forum Members
Posts: 144
Joined: Mon Jun 27, 2005 10:36 am

Re: How can I display News title in Page title ?

Post by fredt »

This patch from Elijah solved my issue : http://forum.cmsmadesimple.org/index.ph ... 50175.html

Thanks A LOT, Elijah !
Post Reply

Return to “CMSMS Core”