Need function help... I am stuck on printing an image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
rprins
Forum Commoner
Posts: 31
Joined: Sat Jun 21, 2003 5:46 pm

Need function help... I am stuck on printing an image

Post by rprins »

Ok, I am trying to write a function that will take the current page via a $PHP_SELF and then print a specific image that is unique for that page on that page. What this is being used for is to give the user some idea where they are on the site via a image between the top image and the content below. I have attmpted to write a function, but I must say I am not well versed in their doing. So, please offer any help to get me on the right path. What I have attempted so far is below.

There will be multiple pages that this is for, but I am just working on getting it to work for one at the moment. Also, I don't know an easy way to get just the index.php from a $PHP_SELF so, that is why I have the $rootpath."test.php" garbage.

Code: Select all

<?php
function print_pagetitle($loaded_page){

	$root_path = "/clanuw_v2/";

	if($loaded_page == $rootpath."test.php"){
		echo "<img src="images/news.gif" width="950" height="65" alt="Page Image">";
		return;
	}
}
?>
Called by:

Code: Select all

<?php print_pagetitle($PHP_SELF); ?>
User avatar
rprins
Forum Commoner
Posts: 31
Joined: Sat Jun 21, 2003 5:46 pm

Post by rprins »

^^ BUMP ^^
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Try using:

Code: Select all

<?php
function print_pagetitle($loaded_page) {
	
	$page_name = basename($loaded_page);

	if($page_name == 'test.php') {
		echo '<img src="images/news.gif" width="950" height="65" alt="Page Image">';
	}

	return;
}
?>
and calling it using:

Code: Select all

<?php print_pagetitle($_SERVER['PHP_SELF']); ?>
On a side note - I would avoid having an image longer than about 700 pixels except in exceptional circumstances - there are still a large percentage of users using 800 x 600 resolution.

Mac
User avatar
rprins
Forum Commoner
Posts: 31
Joined: Sat Jun 21, 2003 5:46 pm

Post by rprins »

Thank You twigletmac!

BTW. The site was asked to be desigened for 1024x768 and this was just for testing purposes to have the image at 900px. It will become smaller down hte line.
Post Reply