Solved

Changing Font Color with PHP According to Page

Posted on 2007-12-04
8
4,046 Views
Last Modified: 2012-06-27
Hello Experts,

I am new to PHP and I am using it to code a website using Wordpress as the CMS.  At the moment, each page has a different title which is displayed just beneath the menu.  I would like to use a different color (colors that I've already chosen) for the text in the title, according to which page it is.  

Meaning, the "pets" page would display the title "Pets" in green lettering...the dogs page would display the title "Dogs" in brown lettering...and so on.  

I am currently working with a combination of css and php...  I've placed the title's php code in a div tag, which is ID'd in CSS to control its font size, etc.  

Is there anyone that knows how one can change the font color for the title, according to which page is being displayed, using PHP?  

Thank you in advance...

Open in new window

0
Comment
Question by:TrickyFingers
8 Comments
 
LVL 16

Accepted Solution

by:
BongSoo earned 168 total points
Comment Utility
You could do it strictly using CSS by putting the individual titles in div tags with unique IDs. that would be easiest.
0
 
LVL 3

Expert Comment

by:Mr_Splash
Comment Utility
If I understand what your asking,.

All you need to do is have a different class for each title, then in each page use the appropriate class name.

or if you want every page to be the same you could do the following in your php, just make sure you set the $title variable first.
if ($title == "pets") {$color = "#11ee00";}

else if ($title == "dogs") {$color = "#994400";}

else {$color = "#000000";}
 

echo"<h1 style=\"color: \$color;\">$title</h1>";

Open in new window

0
 
LVL 1

Expert Comment

by:eXman_pl
Comment Utility
You could use the switch statement, like below.
switch($page){

case 'pets':

   $id='green';

  break;

case 'other':

 id='other';

break;

default:

$id='default';

}
 

echo "<div class='some_class' id='$id'>title</div>";

Open in new window

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Assisted Solution

by:Mr_Splash
Mr_Splash earned 166 total points
Comment Utility
Code correction
if ($title == "pets") {$color = "#11ee00";}

else if ($title == "dogs") {$color = "#994400";}

else {$color = "#000000";}

 

echo"<h1 style=\"color: $color;\">$title</h1>";

Open in new window

0
 
LVL 19

Assisted Solution

by:darron_chapman
darron_chapman earned 166 total points
Comment Utility
I'm assuming you have admin rights to this wordpress installation, if you do, there is a plugin that does exactly that and it wouldn't require you to edit css or php.

http://www.samburdge.co.uk/wordpress/wp-custom-title-colour-plugin  ...

I tested it out and it works as expected... when you click Select Colour, the color chooser is off to the right and you need to scroll over to see it.
0
 
LVL 5

Expert Comment

by:palanee83
Comment Utility
HI
Please see the below code and let me know if it work orif u have any quires
<?php

	//populate all of the available title in an array

	$allowedTitle = array("pets","dogs","birds");

	//get the current page name

	$currentPage = "pets";

	$cssClass = "defaultStyle";

	//here you have to write seperate CSS for each title

	// like petsStyle,dogsStyle,birdsStyle etc

	if(in_array($currentPage,$allowedTitle))

	{

		//if the current page is exists in the allowed title change the CSS 

		$cssClass = $currentPage."Style";

	}

?>

	<div calss="<?php echo $cssClass; ?>">Your Title</div>

Open in new window

0
 
LVL 1

Expert Comment

by:Computer101
Comment Utility
Forced accept.

Computer101
EE Admin
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now