Get database field content and add theme settings menu in wordpress, wordpress field _php Tutorial

Source: Internet
Author: User
Tags import database wordpress blog

Get database field contents and add Theme Settings menu in wordpress, wordpress field


Get_option () function usage tips
Get_option () This function, in fact, we often use in the integration of the background function of a function, mainly used from the WordPress Blog database option table to get the field content we want a function, in most of the current topic, As long as the theme is integrated with the background control page, and most of the use of this function, although WP has given us a lot of ways to temporarily store our theme settings, but with a more stable database to store theme settings or most of the topic authors preferred.

Get_option () function interpretation, usage online or there are a lot of Chinese literature, including official documents This function also has the Chinese version of the explanation, because the use of simple, the idea is relatively clear, so there is not too much explanation.
Official api:get_option
Direct Memo Usage

Tips for use
Usually when we take the setting, we add a judgment, because we don't know if the subject is installed in the system for the first time,

if (!get_option (' Xiangzi ')) {//Determine if there is $default _xiangzi = array (//set a default value first ' title ' = ' blog ', ' name ' = ' ' Xiang zi ', ' url ' = > ' pangbu.com '); Update_option (' Xiangzi ', $default _xiangzi); Set the default value for option} $xiangzi = get_option (' Xiangzi ');//Get Settings

Coincidentally, for some reason, WP officially added a second parameter to the Get_option function for us.
So we can do this.

$default _xiangzi = Array (//set a default value first ' title ' = ' blog ', ' name ' = ' Xiang zi ', ' url ' = ' pangbu.com ') $xiangzi = Get_option (' Xiangzi ', $default _xiangzi);//Is this simple?

Add_theme_page () function-Add your Theme Settings menu
Perhaps you will feel that the official Wordpress default theme, is a very painful theme, ugly style, and poor functionality, there is only shacks Ming this inspirational category of articles to encourage you to use the feeling, perhaps you will feel that this theme in addition to those who will not install the theme of the vegetable vegetable dishes novice use is almost useless , then you are wrong. The main use of the official default theme is to have a great research value, at least my current WP topic knowledge is mostly through the study of the default theme obtained, today is the Add_theme_page () function.

Describe
Add_theme_page () function, add page in WordPress background. Here we are generally to add the settings page to use the function, of course, if you are idle egg pain, you can add a page such as personal description in the background.

Use

$page _title, $menu _title, $capability, $menu _slug, $function These parameters are more commonly used.

Because the Add_theme_page () function is simply too simple to use, let's go straight to the code.

Instance

function Xz_theme_options_add_page () {$theme _page = add_theme_page (' Theme Settings ',//page Titlee ' theme Settings ',//name displayed in background menu ' Edit_them E_options ',   ///Option to place ' theme_options ',    //alias, that is, get transfer parameter ' xz_theme_op_page '//Invoke function to display content call;} function Xz_theme_op_page () {//content display functions echo "I am the Theme Editor page";} Add_action (' Admin_menu ', ' xz_theme_options_add_page ');

Effect

Add a background menu effect

Articles you may be interested in:

    • How to solve the problem that occurs when using the WordPress $wpdb class to read MySQL database to do Ajax
    • The WordPress Import Database appears "Unknown collation: ' Utf8mb4_unicode_ci" error resolution
    • Simple understanding of the use of update_option () functions in WordPress development

http://www.bkjia.com/PHPjc/1091109.html www.bkjia.com true http://www.bkjia.com/PHPjc/1091109.html techarticle in WordPress Get database field content and add Theme Settings menu, wordpress field get_option () function using tricks get_option () This function, in fact we are in the integration background function ...

  • 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.