kcmartz Posted May 25, 2012 Share Posted May 25, 2012 I am in the process of redesigning my site from scratch. I want to have some script so I don't need to keep adding page titles. For example, I want the home page to say "Index | Site Name" and "About Me | Site Name". the 'about me' page would be 'about_me.php' and index.php as index. This would apply to all pages including Contact, and misc pages. Also I want to have dynamic meta tags if possible. Simple-type dynamic. Like for the about page and contact page, things like "This is the (page name) page of Site Name. (Page name) is where you can get information on ___. (page name) blah blah blah..." You see what I mean? I would love something like that for the meta description. Any help will be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/263096-dynamic-php-page-titles-and-more/ Share on other sites More sharing options...
smoseley Posted May 25, 2012 Share Posted May 25, 2012 $title = array(); $filename = __FILE__; $filename = explode(".", $filename); $filename = explode("_", $filename[0]); foreach ($filename as &$part) { if (strlen($part)) $part = strtoupper($part[0]) . strlen($part > 1) ? strtolower(substr($part, 1)) : ""; } $title = implode(" ", $filename) . " | My Site Name"; Quote Link to comment https://forums.phpfreaks.com/topic/263096-dynamic-php-page-titles-and-more/#findComment-1348498 Share on other sites More sharing options...
kcmartz Posted May 25, 2012 Author Share Posted May 25, 2012 Would I put this in a seperate file and include/(require) it or in the header of each file? (Although I think either should work). Quote Link to comment https://forums.phpfreaks.com/topic/263096-dynamic-php-page-titles-and-more/#findComment-1348502 Share on other sites More sharing options...
Kays Posted May 25, 2012 Share Posted May 25, 2012 Structure it using a MVC model. Since you are redesigning your site anyway. Quote Link to comment https://forums.phpfreaks.com/topic/263096-dynamic-php-page-titles-and-more/#findComment-1348511 Share on other sites More sharing options...
smoseley Posted May 25, 2012 Share Posted May 25, 2012 Include will work fine. I had a bug in my code: $filename = __FILE__; $filename = explode(".", $filename); $filename = explode("_", $filename[0]); foreach ($filename as &$part) { if (strlen($part)) $part = strtoupper($part[0]) . strlen($part) > 1 ? strtolower(substr($part, 1)) : ""; } $title = implode(" ", $filename) . " | My Site Name"; Quote Link to comment https://forums.phpfreaks.com/topic/263096-dynamic-php-page-titles-and-more/#findComment-1348554 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.