Create a random calling quote for WordPress widget

Source: Internet
Author: User

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

Recently, the radish fish made a lot of rough WordPress theme, but has not been involved in the production of WordPress Plug-ins, the network on the production of Plug-ins, the information is not much, the radish fish themselves groped, learned a random call famous quotes small plug-ins, although no technical content, But also represents a WordPress plug-in development of a basic step, below, radish fish and netizens share the process of creating this plugin, and we learn together.

The first step, the establishment of a random_words.php file, placed in the Wp-content/plugins, note that Save as Utf-8 mode Oh. This is the content page of our plugin.

The second step, insert your plug-in in the random_words.php of the relevant description text, its format is as follows:

<?php

/*

Plugin Name: A random quote from a turnip fish

version:1.0

Plugin uri:http://www.luoboju.com

Description: A random call of famous quotes

Author:luoboyu

Author uri:http://www.luoboju.com

*/

?>

Note that this should be placed at the top of the file. The standard plug-in information must have at least the plugin name (plugin name) so that WordPress can identify your plugin. Additional information is displayed in the Control Panel plug-in management page. Once you've created it, you'll see the plugin information you just created in the background (as shown in the following image).

  

The third step, the stored data called, that we save the content we need to call in an array, and then randomly call any of the information in this array, the code looks like this:

function Words_generate () {

$words = Array (

' Learn to understand, because only by understanding others can people understand. ',

"Learn to be happy, because only happy to spend every day, live wonderful." ',

When difficulties come, face with a smile, with wisdom to solve. ',

' The weather is not as good as the geographical location. ',

"Mutual tolerant couples must have a century of pillow." '

);

return $words [rand (0, COUNT ($quotes)-1)];

}

We established the Ab_arq_generate () function, which returns the value of any of the famous quotes stored in the array variable $quotes, of course, we need to put the famous quotes that we want to display in an array.

The fourth step, when we enable this plugin, return to any one famous line. The code is as follows:

function Words_change_bloginfo ($text, $show) {

if (' description ' = $show) {

$text = Words_generate ();

}

return $text;

}

Step fifth, use the filter Add_filter () function

Add_filter (' Bloginfo ', ' words_change_bloginfo ', 10, 2);

Well, this simple random quote plugin is over. So how do we call it, oh, simple, a line of code can: please add the above code where you need to call, we look at the results of the local test of radish fish (I was called once on the single page):

  

So far, radish fish has shown you the basics of creating this plugin, but you can also expand it in several ways, such as: if we have more data to deal with? We can choose from the following two scenarios. One: We can add another page that is designed to store the data for the Words_generate () function and include it in the Random_ words.php. Two: Of course we can use a special database table to store, about how to use database tables to access, we will talk about it next time.

Although this is only a very small plug-in, but it shows us at least the production of WordPress plug-ins a basic process, radish fish I also in the study, I hope and friends to progress together. Hey, finally, this article by Radish Home Network http://www.luoboju.com original published, reproduced please specify, thank you!

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.