CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Conditional metatags

Print topic Send  topic

Author Message
pbrad

Posts: 58
Posted: 08/10/2008, 6:35 PM

Hi,

I am trying to dynamically push the Title metatag into the html code of each site page. I have a table called SiteSettings and I have a field called SiteTitle. (I have this working)

In a before show event I run the code:

global $Tpl;
$Tpl->setvar("SiteTitle", GetSiteSettingsParam("Site_Title", "Please set Site Title in Site Settings"));

Then in the head section of the html I place the line:

<title>{SiteTitle}</title>

So now, everything works perfectly. If I have defined the SiteTitle in SiteSettings, it places the site level Title into this page.

i.e. <title>ABC Widgets Inc - Your best source of low cost widgets</title>


However, in addition to having a default site level Title Metatag, I want to be able to define the title metatag at a page level in order to be able to define metatags based on the content of that specific page. (I also have this working)

This is a cms site, so on each page I show a record that contains the viewable/editable html portion of the page code. In each 'page_content' record I have several fields such as meta_title, meta_description, meta_keywords etc... These are hidden fields on the page and then I just enter similar html code in the head of that page

<title>{meta_title}</title>

So now, if the page in question has a record on it that has these fields defined, they are pushed into that pages meta tags.

i.e. <title>ABC Widgets Item 001 - Our fastest, cheapest widget</title>

So finally now to the part that I am struggling with:

What I want is to basically have a hierarchy for the metatags for each page. If the page does have a record with $meta_title in it, I want it pushed into the title metatag and if it doesn't, I want the site level title pushed into the page title metatag, but I don't ever want both values pushed into the title.

I am using the following custom code on a before show event:

if ($meta_title !==""){
global $Tpl;
$Tpl->setvar("SiteTitle", GetSiteSettingsParam("Site_Title", "Please set Site Title in Site Settings"));
}
else
{$Tpl->Setvar("SiteTitle","");
}

and the following code in the head portion of the html:

<title>{SiteTitle}{meta_title}</title>

My logic is that if the page record has the meta_title defined, then show only the meta_title and if it isn't defined, show the SiteTitle. If the SiteTitle isn't defined in SiteSettings then have the title say 'Please set Site Title in Site Settings'.

The problem that I am having is that it is showing both the Site level Title and the Page level title if the page level title is defined instead of only the page level title.

i.e. "<title>ABC Widgets Inc - Your best source of low cost widgetsABC Widgets Item 001 - Our fastest, cheapest widget</title>

Sorry for the long post but could someone please help me with the conditional code that I am using, obviously I am missing the boat here somewhere.

Thanks,
Pete

_________________
Pete

CCS 4
MySQL
PHP
View profile  Send private message
jjrjr1


Posts: 942
Posted: 08/10/2008, 7:45 PM

Hi

Maybe your problem is the syntax of your if statement.

you have

if ($meta_title !=="")

The correct php not equal to is

if ($meta_title !="")

Could that be it?

Let me know


_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
wkempees


Posts: 1679
Posted: 08/11/2008, 5:10 AM

Also (further to John)
Is $meta_title on the page (hidden or otherwise)?
You post it is in BeforeShow that you do your testing, I can see you do the
global $Tpl;
I cannot see where you get your $meta_title from.
It could be
if ( $Component->meta_title->GetValue() != "")
It could be
if ($Component->ds->meta_title !="")
It could even be that you do not have the meta_title in you page SQL in which case you may need to do a CCDLookup()

Walter

(edited)
reread, hidden fields on the page so,
if ( $Component->meta_title->GetValue() != "")


_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
pbrad

Posts: 58
Posted: 08/11/2008, 5:42 AM

Hi again,

It seems that I am making this harder than it should be.

The meta_title is a hidden field on the page form, When I put <title>{meta_title}</title> in the page html it is pulling the correct entry from the record so I am assuming that it is accessible to the custom code:

//Custom Code @11-2A29BDB7
// -------------------------
global $Tpl;
global $SiteTitle;

if ( $Component->meta_title->GetValue() != "")
{

$Tpl->setvar("SiteTitle", "");

}
else
{
$Tpl->setvar("SiteTitle", GetSiteSettingsParam("Site_Title", "Please set Site Title in Site Settings"));
}

//Close Page_BeforeShow @1-4BC230CD


returns error "Fatal error: Call to a member function GetValue() on a non-object in C:\xampp\htdocs\B4You\Content_events.php on line 24" (line 24 is the GetValue line.

Any ideas on what I am doing wrong?

Thanks,
pete

_________________
Pete

CCS 4
MySQL
PHP
View profile  Send private message
datadoit
Posted: 08/11/2008, 6:07 AM

This code is in the Page's BeforeShow. If meta_title is in a record
form on the page, then the record form hasn't been queried yet in the
Page's BeforeShow event.

Put this code in the meta_title BeforeShow or the record form's BeforeShow.

If you put it in the meta_title BeforeShow, you can refer to it as
$Component->GetValue(). If in the record's BeforeShow, refer to it as
$Container->meta_title->GetValue().
wkempees


Posts: 1679
Posted: 08/11/2008, 6:15 AM

DD, well said.
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
pbrad

Posts: 58
Posted: 08/11/2008, 6:25 AM

Got it!

Thanks very much guys. I have it working now and will be incorporating this functionality into the CodechargeCMS pilot project that I am compiling. I will report on general progress over on that forum. http://www.codechargecms.com.

cheers,
Pete
_________________
Pete

CCS 4
MySQL
PHP
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.