Forum Moderators: coopster

Message Too Old, No Replies

How do I do this?

         

jackdack

11:09 pm on Oct 31, 2005 (gmt 0)

10+ Year Member




Scenario, new football website with these main categories
* Teams
* Coaches
* Players
* Results
* Grounds & Stadiums
and probably some more categories to follow.

I need to add tailored content to every page based on the category which that page is in. i.e. a dynamic page title, meta description, meta keywords, category links would all be customised based on the category.
The objective is to make the list of variables (the tailored content) maintainable from one central source. This will simplify maintenance, and mass updates across the site.

What commands/code do I need so that it checks to see for e.g. that the page is in the 'Teams' category, and then pulls all the variable information about Teams? and then when a page on 'Players' is selected, it pulls all the variable information about Players etc.

Is this possible? I presume it must be...I'm new to php, I really appreciate any advice or direction on how I might achieve this

THANK YOU

chrisjoha

11:28 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



You might be best off emplying a content management system (CMS) for this kind of thing. A CMS is basically a system that has all the functionality to define content, and create content types (such as player, stadium and so on) as well as functionality for adding content and managing your application. If needed you'll maybe need to program some extra functionality.

It might seem overwhelming at first, but believe me, the result will be better and you'll most likely spend less time setting up a CMS than writing one yourself. There are a bunch of freely available CMS'es in PHP that shouldn't be too hard to get hosted. I'm still unsure of the URL posting rules here so I'll just name them, you'll find them ;)

Drupal (never used myself but people like it)
eZ (norwegian CMS, very complex and heavy, but also VERY configurable. A little steep learning curve but a great tool)
And one that's really simple: Wordpress. Not really a CMS, but rather a blog software. It's easy to get up and running and easy to configure. It might just be enough for your needs. ('Blogify' your problem: create one category for each type of page - player, stadium and so on. Make the archive for players be the player section and so on. Add custom fields to 'posts' in the player 'archive' that qualifies a player.)

jackdack

3:13 am on Nov 1, 2005 (gmt 0)

10+ Year Member



The way I envisage it working is that every page would have some type of identifier, to distinguish it's category e.g. 'Players category'. Within each page PHP will do a check to see IF this page is part of 'Players' category show 'Players' relevant code.
Is that possible? If so, how? It doesn't sound hard, does it? Thank you

thanks for the post. Implementing a content mgmt solution is not an option at this stage, but i'll certainly look at it later, I appreciate the comments on tools.

dwighty

9:12 am on Nov 1, 2005 (gmt 0)

10+ Year Member



jackdack,

This is just a very basic starter for you but somthing you can work with.

*****index.php****
<?php

// Include Your Header File
include("header.php");

// Set your variable $page
$page = $_GET[page];

// Condition, If no page is selected then it returns the main.php (or whatever you want your main intro page to be)
if($page=="") {
include("pages/main.php");
}

// If a Page is selected then do the following.
else
{
include("pages/".$page.".php");
}

//Include Your Footer File
include("footer.php");
die;
?>

Then in your header.php file for the title of the page
****header.php****
<?php
// define your $head Variable
$head = $_GET[page];
?>
<head>
<!-- If no page is selected the title will echo 'Football :: Main Page'. Otherwise it will echo 'Football :: Season 2005/6'
<title>Football :: <? if($head=="") { echo "Main Page" }
else { echo $head; }
?></title>
</head>

Thats to change the Page Title's. You can work on the same principle for Page Descriptions, but I will leave that for you ;-)

Dwighty

jackdack

9:36 am on Nov 1, 2005 (gmt 0)

10+ Year Member



dwighty, I really appreciate the reply, thank you. It'll take me a little time to comprehend and test as my I'm new to php. I was after some ideas and direction and you've been very helpful, cheers!

If anyone has additional ideas or comments, keep them coming, Thanks

dwighty

10:14 am on Nov 1, 2005 (gmt 0)

10+ Year Member



jackdack,

I am also working on a Football Site (Soccer) so maybe we could work together. Hopefully over the weekend I will be writing a script which will do what i believe you want. We can work through that if you want.

Are you working with a database or not? If not the solution would be to define variables e.g.

$Coachs = "An Overview on all of the Coachs in the Game";

Or something like that...

More to follow.

In the mean time, if anyone can suggest different ways to approach this that would be good.

Dwighty

jackdack

8:15 pm on Nov 1, 2005 (gmt 0)

10+ Year Member



No database. Not at this stage. I prefer to use flat files. ta

jackdack

1:03 am on Nov 2, 2005 (gmt 0)

10+ Year Member



Just thinking about one part of this challenge - including specific links for each category - can I declare a variable on each page e.g.

$category=players //for pages about football players

and then have the following code in all pages

if($category=="players") {
include("players_links.php");
}

else

if($category=="teams") {
include("teams_links.php");
}

else

if($category=="coaches") {
include("coaches_links.php");
}

else

{
include("no_links.php");
}

Syntax may need some fixup but in principle would that work? Thanks

dwighty

12:04 pm on Nov 2, 2005 (gmt 0)

10+ Year Member



jackdack,

Yes the principle will work and thats probs the best way to do it. Although all you including are the files.

If you have a common header.php file then the description will still be the same.

If your players.php file includes the <html><head>& meta tags then will be fine.

Dwighty

jackdack

6:26 pm on Nov 2, 2005 (gmt 0)

10+ Year Member



I've since read up on the SWITCH statement which looks to be a better option