Skip Navigation

[Resolved] Customizing partial site content with Types, Views and a URL variable

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 8.59 hours from now. Thank you for your understanding.

This topic contains 2 replies, has 2 voices.

Last updated by David 8 years, 4 months ago.

Assigned support staff: Caridad.

Author
Posts
#91056

I'm basically done building a site with Types and Views but am needing some assistance going the last mile. I need to be able to customize certain parts of the site (header logo, footer info like phone/email, and some additional content on another page) by utilizing a URL variable such as hidden link

Basically, this site is going to be launched in another window from different client web sites who would have a specific ID (i.e. 352). My site would then know how to load the content specific to that client (logo, etc.).

I've constructed a Custom Post Type called "Members" which has a variety of fields defining the content specific to them (image field, email field, WYSIWYG fields, etc.) Currently I'm thinking of having the URL variable be equal to the Post ID and somehow using the WordPress get_post_meta() function but that's where I get lost. I would love to use Views somehow since I'm not savvy enough with PHP but since I'm customizing elements in my header.php, footer.php, and page template file, I feel like I need to be manually integrating these in the backend.

Can anyone provide some useful feedback on how to approach this? Ideally I would love to even define a custom field where I can generate my own "member ID" and not use the post ID that gets created publishing the content.

Thank you!

~david

#94368

Dear David,

Using the post_id is a good idea, you can use this sort of code in a theme file to print the fields:

$member_id = (int)$_GET['id'];
if (!empty($member_id)) {
echo get_post_meta($member_id, 'wpcf-slogan', true);
} else {
  echo 'This is the default slogan, when no id is in the url';
}

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.

Regards,
Caridad

#94377

Caridad-

Thank you for your response. I was able to get things working with the following code if anyone else is interested.

Placed at the very top of my header.php file

	global $memberID; // declare global variable for the member ID
	global $memberHex; // declare global variable for the member color

	if($_GET['id']) : // if URL variable is present...
		$memberID = $_GET['id']; // set $memberID to this variable.
		$expire=time()+60*60*24*30; // set cookie to expire in 30 days
		setcookie("designedID", $_GET['id'], $expire);
	else :
		// if no URL variable is present, check to see if our cookie is present
		$memberID = $_COOKIE["designedID"];
	endif;

Then I have assorted code throughout my header, footer, and/or page template files similar to the following (utilizing WordPress' get_post_meta() function):

	<?php $member_logo = get_post_meta($memberID, 'wpcf-member-logo', true); ?>
	<?php if($member_logo != '') : ?>
		<div>
			<a href="<?php echo home_url( '/' ); ?>">
				<img src="<?php echo $member_logo; ?>" alt="" />
			</a>
		</div>
	<?php endif; ?>

I don't live and breathe PHP coding so perhaps what I've shown above is not the best, but it does work for my needs at the moment.

Additionally, I can't say enough good things about your family of plugins. I've only scratched the surface on their depth and they've already allowed me to build much more complex sites with ease. Thank you all for your hard work.

~david