Jump to content

Cre8asiteforums Internet Marketing
and Conversion Web Design


Photo

Using Variable Values In Wordpress


  • Please log in to reply
13 replies to this topic

#1 mrgoodfox

mrgoodfox

    One Who Engineers

  • Moderators
  • 1014 posts

Posted 19 July 2011 - 10:00 AM

Is it possible to add fields in WordPress database (without having future upgrade issues) to have values in them that is being used in the template's code?

For example, I want to put my client's social media links in them, so that when the client wants to edit those links she doesn't have to go look into the code and can simply go to a Setting page and update those links (or phone number or any other such information)

#2 jonbey

jonbey

    Eyes Like Hawk Moderator

  • Moderators
  • 4410 posts

Posted 19 July 2011 - 10:45 AM

You should be able to add additional widgets to a template that the client can then access through the widgets page. I wrote a blog about it on webo a while back but fear that it is specific to only a few template types.

#3 Michael_Martinez

Michael_Martinez

    Time Traveler Member

  • 1000 Post Club
  • 1354 posts

Posted 19 July 2011 - 01:55 PM

If it's not a capability in your client's theme's widget set, there are plenty of plugins that create this capability.

#4 mrgoodfox

mrgoodfox

    One Who Engineers

  • Moderators
  • 1014 posts

Posted 20 July 2011 - 05:10 PM

Can you name one or two of the plugins? What do I search for to find them?

#5 AbleReach

AbleReach

    Peacekeeper Administrator

  • Site Administrators
  • 6467 posts

Posted 20 July 2011 - 05:13 PM

Search the plugin area @ WordPress for terms related to [social media] - seriously, there are lots.

#6 Michael_Martinez

Michael_Martinez

    Time Traveler Member

  • 1000 Post Club
  • 1354 posts

Posted 20 July 2011 - 05:30 PM

Yeah, there are dozens, probably hundreds of them. I use a few like "WP Social Bookmarking Light", "Share This", and "Plus One" but you need to review each plugin for yourself and make sure it fits in with what you're doing. Some of the social media buttons I'm displaying don't look quite right. A real Web designer would have a better idea of what to look for to match the theme, I think.

#7 mrgoodfox

mrgoodfox

    One Who Engineers

  • Moderators
  • 1014 posts

Posted 23 July 2011 - 02:14 PM

I did search a lot. I didn't find what I needed.

Its not just social links. There are a bunch of information that i'd like to use variables for instead of hard coding it (or sometimes hard typing it in a post).

I ended up using a plugin for search and replace. not exactly what i was looking for but gets the job done

#8 AbleReach

AbleReach

    Peacekeeper Administrator

  • Site Administrators
  • 6467 posts

Posted 23 July 2011 - 04:52 PM

Which variables apply will depend on exactly what you want to accomplish.

#9 DonnaFontenot

DonnaFontenot

    Peacekeeper Administrator

  • Site Administrators
  • 3821 posts

Posted 23 July 2011 - 09:07 PM

I'm thinking you might mean using custom fields.

http://codex.wordpre...g/Custom_Fields

http://www.wpbeginne...icks-and-hacks/

#10 Guest_joedolson_*

Guest_joedolson_*
  • Guests

Posted 24 July 2011 - 10:07 AM

If you want to use custom fields, the easiest thing is to probably add a function to your theme's functions.php file to fetch the custom data:


if ( !function_exists('get_custom_field') ) {
	function get_custom_field($field) {
		global $post;
		$custom_field = get_post_meta($post->ID, $field, true);
		echo $custom_field;
	}
}


Usage:


<?php get_custom_field('some-custom-field'); ?>


If you want to be able to use it within the content of the post, you could register it as a shortcode:


function custom_field_shortcode($atts) {
	extract(shortcode_atts(array(
				'field' => 'default-custom-field'
			), $atts));
	return get_custom_field('field');
}

add_shortcode('my_custom_field','custom_field_shortcode');


Usage (in a post or page):


[my_custom_field field='some-custom-field']



#11 mrgoodfox

mrgoodfox

    One Who Engineers

  • Moderators
  • 1014 posts

Posted 24 July 2011 - 04:26 PM

Joe,

Thats exactly what i was looking for. I guess i was (am) too dumb to write that code myself. I appreciate your help.

What file would I put the function itself? Also, when I use the "In Post" code would it work when switching back and forth between HTML and Visual mode in Wordpress? I've seen some codes that work in HTML but as soon as switched to Visual mode they get all funky or not work.

#12 Guest_joedolson_*

Guest_joedolson_*
  • Guests

Posted 25 July 2011 - 12:36 PM

You'd put those functions in the 'functions.php' file within your theme. If your theme doesn't have a functions.php file, you can create it - just wrap the code above in php tags (<?php ?>) and upload the file.

And yes, those shortcodes should be just fine regardless of mode. Visual mode messes up HTML, and can mess up some non-standard shortcodes (shortcodes not using the WordPress shortcode engine), but this would be fine.

#13 leadegroot

leadegroot

    New To Community

  • Members
  • 2 posts

Posted 31 July 2011 - 01:26 AM

sorry, a bit late to the party but...

Custom fields are for per-post items.
You probably want to add something to the options table.
I'm afraid its going to take come coding - you are probably better trying to find an existing plugin that suits. Try searching for one of the actual social media service name plus wordpress plugin.
If you want to try the custom route, this might be a starting point for you:
http://codex.wordpre...g_Options_Pages

#14 mrgoodfox

mrgoodfox

    One Who Engineers

  • Moderators
  • 1014 posts

Posted 28 August 2011 - 01:55 PM

I ended up using a plugin called "Search and Replace" which accomplishes the same end goal (a little more work than desired but definitely not hard at all)



RSS Feed

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users