Jump to content

Recommended Posts

I hope some one can help. I'm not a guru on PHP. I'm creating a web site for a non-profit org. The org. has alot of pages with little text content on them. I wanted to create 1 (one) php, with various content. I would create links on the page and when clicked that section would show. I had something like this a very long time ago and can't find it and asking if someone can point me to a web site with a tutorial on this.

Hope someone can help.

 

tks

tripleaaa

Link to comment
https://forums.phpfreaks.com/topic/52846-need-php-help-text-content/
Share on other sites

this shouldn't be a problem at all, i've done a fair few of my pages like this.

 

so, you can change the text like below; the links are e.g. www.cardsunlimited.com/greetingscards.php?purpose=officegreetingcards

 

Just use if statements coupled with links to e.g. www.example.com/page.php?customer=charity

 

that sets $_GET['customer'] to 'charity'. on page.php, you use an if statement to get the $_GET value and echo text appropriately.

 

if you get stuck i can give you more php by PM

 

 

<div id="middle">
<table  border="0" cellpadding="0" cellspacing="0">
		<tr><td>
		<?php
		if ($_GET['purpose']=='officegreetingcards') {
			echo '<div id="h1"> Office greeting cards </br></div>
			<div id="blurb">Are you the person who has to pop out and buy all the greeting cards for people at work? Are you paying £2 a pop? Crazy, isn’t it? </br></br>
			On this site, you can buy individual greeting cards for £1.20 each, packs of 5 mixed cards for £1 per card, or packs of 25 same-design cards for 50p per card. Click on a design you like, and the options - including mixed packs - will pop up, as if by magic!</br></br>If you know you would like only Birthday, or Get Well cards, please use the Message dropdown to your left.';
		}
		elseif ($_GET['purpose']=='hotelgreetingcards')
		{
			echo '<div id="h1"> Hotel greeting cards </br></div>
			<div id="blurb">Our greeting cards are used in several prestigious hotels within the UK. </br></br>
			Greeting cards may be given to guests to welcome them, or to help celebrate a guest’s birthday or anniversary. Prices start from just 50p. Please click on a design you like to display the packaging options and prices. If you would like to narrow down the results, please use the dropdowns to your left.';
		}
		else
		{
		echo '<div id="h1"> Greeting cards </br></div>
			<div id="blurb">We stock over 80 designs of greeting cards, all photographic, all square, and all available to you as a consumer from 50p, or as a retailer from 65p (individually wrapped in cellophane). Click on any of the images to see whether the card is available blank or messaged, and to see what the pricing options are.</div>';
		}
		?>
</div>

tks marmite and taith,

taking the codes you have mentioned. I create example links: Home, About us, Contact Us etc.... What statement would I use to link the content. Also can I add tables and images in the echo statment. Do not mean to be dumb on this.. Just not an expert.

 

Pls confirm

 

And tks for helping me out this a great ++++++++++

 

tks all

trippleaaa

search engines read the resulting html, not the php that spews out the html.

 

so anything in the html is search engine friendly. links that use text rather than images are always better!

 

NB if your page is called www.example.com/page.php?id=123 google will only look at www.example.com/page.php (i think), and not look at the page as a whole ?id=123, or consider it a separate page.

 

This means two things: (1) submit them a SITEMAP. this is really important in terms of SEO. google have loads of info on making a sitemap.xml (you can just copy their example and modify it), and (2) make sure that page.php has something on it, a "default" content, e.g. in your if stmt, do "if (it's a charity) { put this text } elseif (it's something else) { do this } else { (do this) }

 

Make sure you have an "else" and not just all "elseifs", that way page.php will always have some content for search engines that can't see your page.php?id=123

 

good luck!

Without trying to complicate things for a n00b, may I suggest using a basic XML file to store optional content. May seem overkill now (I don't think so, but one could), but it will make your life easier when you decide you need a CMS.

 

$dom = new DOMDocument;
$dom->load('file.xml');
$fragment = $dom->getElementById($_GET['purpose'].'greetingcards');
$fragment->removeAttribute('xml:id'); 
echo $fragment;

 

<content>
<div xml:id="officegreetingcards">
	<div id="h1"> Office greeting cards</div>
	<div id="blurb">Are you the person who has to pop out and buy all the greeting cards for people at work? Are you paying £2 a pop? Crazy, isn’t it? </br></br>
		On this site, you can buy individual greeting cards for £1.20 each, packs of 5 mixed cards for £1 per card, or packs of 25 same-design cards for 50p per card. Click on a design you like, and the options - including mixed packs - will pop up, as if by magic!</br></br>If you know you would like only Birthday, 
		or Get Well cards, please use the Message dropdown to your left.
	</div>
<div>	
<div xml:id="hotelgreetingcards">
	<div id="h1"> Hotel greeting cards</div>
	<div id="blurb">Our greeting cards are used in several prestigious hotels within the UK. </br></br>
			Greeting cards may be given to guests to welcome them, or to help celebrate a guest’s birthday or 
			anniversary. Prices start from just 50p. Please click on a design you like to display the packaging options 
			and prices. If you would like to narrow down the results, please use the dropdowns to your left.
	</div>
</div>	
<div xml:id="greetingcards">
	<div id="h1"> Greeting cards</div>
	<div id="blurb">We stock over 80 designs of greeting cards, all photographic, all square, and all available to 
			you as a consumer from 50p, or as a retailer from 65p (individually wrapped in cellophane). Click on any of the 
			images to see whether the card is available blank or messaged, and to see what the pricing options are.
	</div>
</div>
</content>

 

Naturally you don't actually use $_GET that way. And you'll have to be a little smarter in grouping and loading content when you get more content (because the whole file is loaded in memory using DOM).

Thanks marmite and 448191.

Ok I tried the code marmite posted and that works fine. Now with XML I'm really lost.

1. Do I create a file with a php ending with:

<?php

$dom = new DOMDocument;

$dom->load('file.xml');

$fragment = $dom->getElementById($_GET['purpose'].'greetingcards');

$fragment->removeAttribute('xml:id');

echo $fragment;

?>

 

2. Then create a file with the content for XML with an ending file name of file.xml?

 

Sorry for all the questions.

Thank you again for your help

 

You know what; it's at this point probably easier to forget about XML and use simple filename based includes instead.

 

i.e.:

 

<?php
ini_set('open_basedir', '/home/blah/devroot');
ini_set('include_path', get_include_path().DIRECTORY_SEPARATOR.'/home/blah/devroot/html');
?>
<html>
...
<?php
if(isset($_GET['page']) && !empty($_GET['page'])){
$file = 'content/'.$_GET['page'].'.php';
if(file_exists($file)){
	include $file;
}
	else {
	include 'error/404.php';		
}
}
else {
include 'content/default.php';	
}
?>

 

The benefit to this over using echo's is that you can have someone edit the HTML without having to know (possibly screwing up) php.

 

Another interesting idea would be to use a script without an extension, sort of like Wikipedia does.  So instead of http://en.wikipedia.org/wiki.php?topic=PHP you use http://en.wikipedia.org/wiki/PHP, and the script takes "/PHP" as an argument like a query string, but it looks like it's part of the filesystem.

 

It's needlessly more complex than using a query string, but the URLs look nicer.  If you're interested in using this method, see some of the user comments under Hiding PHP in the docs.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.