The magical uses of WordPress custom fields

Source: Internet
Author: User

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

Using WordPress has been a while, in the process of building my blog, I have accumulated a lot of experience, I have a custom field for WordPress is like, with a custom field, you can complete a lot of custom functions.
Custom fields are seen every time a new journal is published (the following figure). How to use this problem is already very old, most people will, a few new users can search Google: lol One of my suggestions is to build a custom field as a new field in the database, and then call in the topic. This article is mainly about the custom field of some magical use, it can be said to be some summary, plus some of their own often used experience.


Clever use WordPress custom field to define META tags (can be a small SEO)

When publishing the log, in the name of the custom field to define keywords and description (of course, you can also name), in the value of the article to fill in the keywords, description information. And then you can call the.

the following references:


<?php if (Is_single ()) {?>


<meta name= "keywords content=" <?php $key = "keywords"; Echo Get_post_meta ($post->id, $key, true);?>/>


<meta name= "description" content= "<?php $key =" description "; Echo Get_post_meta ($post->id, $key, true);?>/>


<?php}?>


This can be called, very simple, if you do not use SEO plug-ins, so there are certain benefits to SEO, of course, can also replace Plug-ins.

Use a custom field to add a category theme picture to WordPress

Now there are some information sites or some blog sites above each piece of news or the log has a theme picture (below), this function through WP's custom field can be done. I'll give you an example of the following picture.



First in the custom field to create a new field "Topic_img", the value of the inside to fill in the image you do the address, and then in the theme of WP call on it.

the following references:


<?php if Get_post_meta ($post->id, ' Pre_image ', true):?>


<?php $image = Get_post_meta ($post->id, ' Pre_image ', true);?>


<img src= "<?php echo $image?>"/>


<?php Else:?>


<img src= "<?php bloginfo (' template_directory ');? >/images/blank.jpg"/>


<?php endif?>


You will see the above code, line 5th is to define the default image that is displayed if no value is entered, you can define the address yourself. Of course, you can also add width,border to the picture, or define other styles, can be done according to their own liking.

Use custom fields to add anything you need

If you want to use WP to build a non-blog site, the article you publish must need something else, such as you want to do a Amoy site, then you definitely need to add the price of goods, promotional links or more you want, or the same reason, published when the custom field, and then called in the theme. Not a few examples.

When I wrote this, I suddenly had an idea that might help a friend who wanted to put an ad in a blog. Some bloggers will put different ads based on different topics, this can also be implemented using custom fields, is to build a "advertise" custom fields, and then can be called to implement, this feature can be used with some advertising plug-ins, The default advertisement is displayed when the custom field is not entered.

WordPress's Custom field is really very powerful, so that you do not have to modify the program to do a lot of complex work, so that build station to become simpler.

Original link: http://www.atmoment.cn/wordpress/wordpress-custom-fields

Related Article

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.