• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Help with PHP includes and passing variables

Confused

Elite Member
Hi all,

This is my first step into creating a web page with PHP, and I've just got one little problem that I'd like to try to address 🙂

I've got the main page (main.php) which I'm trying to use to show all the other pages, so that any layout or design changes (that exist outside of CSS modifications) can be done without having to modify the content pages, they will be as plain as possible.

The biggest problem I'm having is trying to set the page Title dynamically for each individual content page. The only way I've been able to do this so far is to include the header from the relevent content page, but that isn't ideal as I can't just point a browser to /pages/page.php and get a content-only version of the page (like I've seen some other sites do).

I'm also helping out someone else at work with designing a similar site, after he saw my layout/design, but want to get these problems sorted out.

Attached is the current code, and modifications that could be made will be greatly appreciated 🙂


Thanks in advance 🙂
 
I assume you're passing a variable to determine what content page you will show, correct? How about, based on that variable, you display a different title? So in the header of the 'shell' page you just have a long 'if' statement that you can also use to determine which page to include:
 
Yeah, I am passing variables to say which page to display.

However, I was trying (if possible) to get away from a huge If statement in the header, but if that's the only way around it then it's the only way around it.
 
Of course, if you're using a mysql database, you could store the page names and content in there instead of having to do it through includes... then you'd just have to write a quick query to pull all the info out of the db.
 
Yeah, that might be the next stage, but I'm only just learning PHP and CSS/HTML, so MySQL is alien to me 😉 But i suppose it's a logical step! 😉


Garry
 
Rather than using a db or an if else statement, just put all your possible values for pages into a hash as so:
 
Back
Top