Saturday, May 19, 2012

How to Add Multiple Signatures to WordPress Blog using Custom Fields

Attention: open in a new window.  E-mail

Objective: To have the option to choose which signature image to insert as part of your blog post using custom fields in WordPress Blog Post.

Defination:

This is a sample code to implement different image signatures in your blog post based on a defined variable called "sig" from the custom field.

Instructions

  • Step 1: Create a folder in your website root directory called "authors".
  • Step 2: Upload the signature image files. (For this example we have 3 difference signatures)
  • Step 3: Edit the code below to reflect the name of the image signature files
  • Step 4: Insert the code in Main Index Template (index.php) such that it is after your blog post & before your tags or comments code. 

e.g.

<--- Blog Post Content Code here --->  - Usually: <?php the_content(__('Read more', 'studiopress'));?>

<--- Copy code here --->

<---tag code --->

For this example, I am using the 1 or 2 to determined if i plan to use signature 1 or 2 respectively. If I do not define a number it takes the default signature "3" as the main signature.

  <?php
	//This part of the code inserts the value pulled from the custom field ("sig") in the blog post of WordPress to the variable "$signature"
	
	$signature = get_post_meta($post->ID, 'sig', $single = true);
	
	// This then does a check to see if signature 1 is needed
	if ($signature == "1")
	{
		// Input your 1st signature file name
		echo "<img src='/authors/avatar_1.png' />";
	}
	
	// This then does a check to see if signature 2 is needed
	elseif ($signature == "2")
	{
		// Input your 2nd signature file name	
		echo "<img src='/authors/avatar_2.png' />";
	}
	
	// This then loads signature 3 as defauly as signature 1&2 condition was not fulfilled
	else
	{
		// Input your 3rd signature file name
		echo "<img src='/authors/avatar_3.png' />";
	}
?> 


Hope this helps everyone as it works great for me.

 

Andrew

 


Andrew Boey
Written on Sunday, 05 December 2010 04:40 by Andrew Boey

Viewed 804 times so far.
Like this? Tweet it to your followers!

Rate this article

(0 votes)

Latest articles from Andrew Boey

Latest 'tweets' from YourJoomlaTraining

  • Just Upgraded my MacBook Pro RAM from 4GB to 8GB for US$115 and the memory performance rating was better than stock! Link Sunday, 13 February 2011 21:09
  • Come to "Create Your Online Real Estate - Generate Passive Income and Capital Gains " Friday, February 11 from... http://fb.me/RJlR4Bka Link Monday, 31 January 2011 06:27
  • I posted 20 photos on Facebook in the album "Website Mastery - March 2010" http://bit.ly/bjkO0X Link Tuesday, 23 March 2010 21:22
  • Come to "Website Mastery Intro" Tomorrow from 6:30 pm to 10:00 pm. Website Mastery Intro - Start Your Online Real... http://bit.ly/aeTZAr Link Friday, 05 March 2010 01:02
  • Message: "Register Now! for 3rd Joomla! 101 Intensive - Sat - 17th Oct - 9:00am to 5:30pm" - http://grsnip.com/INPh Link Sunday, 04 October 2009 01:34
blog comments powered by Disqus

Members Login