When the 1 typecho plug-in Digg is used to build typecho, a plug-in Digg is downloaded from the official website. After the plug-in is installed, it can be activated and configured in the background, but the foreground remains unchanged. What's going on? I thought I was wrong when I started to configure the plug-in. I repeatedly reviewed the plug-in usage tutorial and did not understand what was going on. So I suspected the code was faulty and went to the plug-in compilation tutorial.
1. When the typecho plug-in Digg is set up, a plug-in Digg is downloaded from the official website. After the plug-in is installed, it can be activated and configured in the background, but the foreground is unchanged. What's going on? I thought I was wrong when I started to configure the plug-in. I repeatedly reviewed the plug-in usage tutorial and did not understand what was going on. So I suspected the code was faulty and went to the plug-in compilation tutorial.
1 typecho plug-in Digg
When typecho is set up, a plug-in Digg is downloaded from the official website. After the plug-in is installed, it can be activated and configured in the background, but the front-end does not change. What's going on?
I thought I was wrong at the beginning, and I did not understand what was going on in the plug-in usage tutorial, So I suspected that the Code hadProblem, Go to the plug-in compilation tutorial, HelloWord. For details, see here.
1. the plug-in analysis plug-in function is used to output welcome words in the background menu navigation bar after a user logs on. So what we need to do is to find the background menu file, whether there is a plug-in interface that provides such features. In general, which interface is used to implement the function depends on the plug-in we want to write, which functions are used, or what effects are implemented to determine, and then find the corresponding file. Fortunately, we found the following interface in/admin/menu. php, which is about 7th lines:
NavBar ();?> This is the interface code to be written in the activation plug-in. Plug-in interface, usually in the following two ways: Typecho_Plugin: factory ()-> function (); $ this-> pluginHandle ()-> function (); after finding the interface code, we will start to compile our plug-in code. 2. Write the code in the order in which the code is usually written. The code is basically written in the order in which the default method appears. Therefore, we first start to write the code for activating the interface: public static function activate () {Typecho_Plugin: factory ('admin/menu. php ')-> navBar = array ('helloworld _ plugin', 'render ');}
In the activate function of the plug-in, the program will get a plug-in function to call the render function in its own plug-in.
However, the activate function in the Digg plug-in has no Code except for operating the database. How does this affect the front-end display. Continue to read the code. There is an output function in Digg.
/*** Output method ** @ access public * @ return void or array */public static function output ($ return = false, $ dump = false) {// prevents inactive plug-in output errors. Comment out $ all = Typecho_Plugin: export (); if (! Array_key_exists ('digg', $ all ['activated']) {return;} // get related settings $ setting = Helper: options () -> plugin ('digg'); $ items = explode ('|', $ setting-> items); $ items_echo = explode ('| ', $ setting-> items_echo); if (count ($ items )! = Count ($ items_echo) | empty ($ items [0]) {echo "plug-in project configuration error"; return ;}// digg submit address $ post_url = Typecho_Common :: url ('Action/digg', Helper: options ()-> index); // Digg emoticons $ img_url = Helper: options ()-> pluginUrl. '/Digg/img/'; // obtain the log digg data $ db = Typecho_Db: get (); $ cid = Typecho_Widget: widget ('widget _ archive ') -> cid; $ rows = $ db-> fetchAll ($ db-> select ('item', 'Count')-> from ('table. digg')-> where ('cid =? ', $ Cid); $ result = array (); $ result ['items'] = @ array_combine ($ items, $ items_echo ); $ result ['imgurl'] = $ img_url; $ result ['cid'] = $ cid; $ result ['Count'] = 0; foreach ($ rows as $ k => $ v) {if (isset ($ result ['items '] [$ v ['item']) {$ result ['Count'] + = $ v ['Count']; $ result [0] [$ v ['item'] = $ v ;}} // print_r ($ result); unset ($ rows); // output js and css echo $ setting-> src;/* usage 1
You can also modify the output format by yourself */if (! $ Return) {echo""; Foreach ($ items as $ k => $ v) {echo''; echo $ result ['items '] [$ v]; echo '('. (isset ($ result [0] [$ v])? $ Result [0] [$ v] ['Count']: 0). ')';} echo'
'; Return;}/* usage 2
Returns digg data in an array. You can add the parameter "true" to the custom html structure to view returned data */if ($ dump) var_dump ($ result); // var_dump return $ result ;}
This section describes usage 1 and usage 2. This makes it clear that the usage 1
Put it in the front-end template page, as shown in figure
In this way, each article on the front-end homepage has the top-step function.