Question about using include() to pull data from a separate php page
-
I’ll see if I can pose my question correctly.
I am setting up pages for members of a legislature. Each member will have several pages (newsletters, district information, bio, etc) and each member’s page will have the same menu and picture and contact info at the top.
So member A will have a newsletter page, a district info page, etc each with his/her address, picture, and menu of pages at the top.
Member B will have the same thing, but with their picture, address, menu, etc.
And so on.
I set up a template to handle inputting that info at the top of each page automatically using the include function similar to this. I created a variables.php page like this:
<?php $memberAdistrict = '04'; $memberAaddress = '123 Main Street'; $memberApicture = 'images/memberApicture.jpg'; $memberBdistrict = '36'; $memberBaddress = '456 Elm Ave'; $memberBpicture = 'images/memberBpicture.jpg'; ?>
And then coded the template using that data:
<?php the_title(); ?> represents district <?php include 'variables.php'; echo "$memberAdistrict"; ?> <p>Address: <?php include 'variables.php'; echo "$memberAaddress"; ?> <p><img src="<?php include 'variables.php'; echo "$memberApicture"; ?>
What I would like to do, if it’s possible is use the same template for every member, and not have to create a separate page template for all 44 members.
What I’m thinking that requires me to do is edit
<?php include 'variables.php'; echo "$memberAaddress"; ?>
to link up with the page’s title. So if my pages are titled memberA and memberB, I want to do something like changing the variable in the above code from
"$memberAaddress"
to
"$<?php the_title(); ?>address"
But I know that isn’t proper and won’t work. Does anyone have a solution that accomplish what I’m looking for? Or a reference page to send me searching to?
Thank you for any help, I hope I can across making some sense.
- The topic ‘Question about using include() to pull data from a separate php page’ is closed to new replies.