wp blog digonto10-29-2011

April 27, 2022 . 2 MIN READ

Reference

Make your content more manageable with custom fields in simple way:

Suppose you want to put your facebook, twitter, linkedIN or flicker profile link as follow us in your site and want manage it from admin panel. What you have to do, just create five custom fields in a post and take the profile URL from that post. Use the URL for each icon as links. I am going to explain the process using a very nice and easy plugin Advanced Custom Fields.

 

 

Steps to do:

  1. Download and install the plugin from here http://wordpress.org/extend/plugins/advanced-custom-fields/. Activate the plugin through admin panel. You will get the plugin option under settings menu.
  2. Click Adv Custom Fields > click Add new > Enter title for custom field group.
  3. Click Add field > Fill the required fields Label, Field Name, Field Type. In this case you can take the field type as text. Additionally you can put some instruction for the field.
  4. Don’t forget to assign the field to an appropriate post type. By default the field will appear in post. If you want to show it in pages edit screen or your other custom post type than you have to assign it for page or to your custom post type.
  5. Repeat step 3 and 4 to create five fields.
  6. Clicks publish. Now it will look like the image below

 

 

  1. Use tag the_field(field_ name) or get_field(field_ name) inside your query loop to retrieve the value of the field. Optionally you can visit plugin site to see more query tag.

Here is an example how I query and use the data. For this I create a post and category then use the query like that.

$the_query = new WP_Query(array(‘post_type’=>’post’,’cat’=>4));   

                                 while( $the_query->have_posts() ) : $the_query->the_post();

                                                $facebook=get_field(facebook);

                                                $tweeter=get_field(tweeter);

                                                $linkedin=get_field(linkedin);

                                                $flickr=get_field(flickr);

                                endwhile;

  1. Now echo the variables where you want use the urls. That’s it.

Leave a Reply

Your email address will not be published. Required fields are marked *