WordPress custom field to achieve the business website price list function

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

WordPress allows the journal writer to assign custom fields to the log. By customizing the fields, we can easily add extra content to the log or page and change the way information is displayed quickly.

Before the formal study, let's take a look at the database structure of the custom field to lay the groundwork for the learning behind.

First, we open the phpMyAdmin, in fact, the custom field is stored in the Wp_postmeta table, the structure of the table is very simple. It has only four fields: Meta_id,post_id,meta_key and Meta_value.

The following figure:

  

META_ID: is automatically generated by a custom field ordinal number, we do not need to ignore it (such as the meta_id in the above figure is a row of 342).

POST_ID: Is the ID of the current custom field's information link to the log (post_id is a record from the Wp_posts table, such as 115 in the above figure). We can correspond to a specific article through post_id.

The name of the Meta_key:key is the description of the information you want to attach to the log (for example, the price in the image above: "Prices", etc.).

Meta_value: The value associated with the key is the actual content of the custom field information (for example, the key value associated with price in the above figure is ' 300 yuan ').

E-commerce website or Taobao site, there are generally product pictures and the price of the product introduction, product pictures, products can be included in the wp_posts6184.html "> datasheet, but we would like to put the price of products alone, placed in the picture below a conspicuous place to display alone, What do we do? Now we can use the function of the custom field of WordPress to realize the price call of the following figure.

  

Below the radish fish begins to learn how to use the WordPress custom field to create a display of the quote information for an ecommerce site and display it. (For example radish fish radish Home network http://www.luoboju.com Use this function.) )

First, add the custom field information:

We plan that the key name of the custom field that needs to be added is called ' price ', which is the value of the key by defining the key, and the valued key is 300 yuan.

How to implement the above key and value distribution in wordpress background?

1. After writing a good log, drop down to the place where the custom fields are written (named Fields).

2, now to create a custom field named "Price", enter the text price in the text entry area labeled key.

3, now will assign a value for the new key, in the Value field, enter 300 yuan.

4. Click the Add Custom field button to save this custom information for this log.

  

Display the contents of a custom field on the page:

We'll show them when we've finished adding custom fields. To display the custom fields for each log, you need to use the

Get_post_meta () function: Get_post_meta ($post _id, $key, $single);

$post _id is the journal ID used by the custom field. Use $post->id to get the ID of a log.

$key the key name of the custom field, such as ' price ' above us.

$single can be true or false. If set to True, the function returns the result of a single string form. If False or not set, the function returns an array of defined fields that WordPress allows you to use the same custom field key in many logs, and you can "group" by changing "$single = True" to "$single = false" These keys.

After explaining the above function, let's look at how we can display the value of price 300, which we defined above, in the location of the page you want to display, and we'll add the code to the appropriate location in the page:

Prices: ID, "price", $single = true);?>

Third, test display results:

Radish fish in the local test two blog posts, one for the price of 300 yuan, the other one for the price of 500 yuan, the local test results are shown as follows:

  

End: Many times, by using custom fields, you can attach additional information to logs and pages and quickly change the way information is displayed. Hey, this is the point today, I do not know that we have learned? Finally, this article by the home network of radish original + local test, reproduced please indicate the small radish Fish blog: Radish Home network http://www.luoboju.com, thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.