WordPress through ajax way to obtain sidebar information

1, first have to load jquery library;
2, in their own to write the js file to write:
function ajaxs () {
$ .ajax ({
url: ‘http://127.0.0.1/?action=ajax’, // domain name replaced with what you want to use
type: ‘get’,
beforeSend: function () {
var loading = ‘<span class = “loadsidebar”> </ span>’;
$ (‘# hotposts’). empty (). html (loading) / / loading loading ah God horse
},
error: function (a) {
$ (“# hotposts”). hide (). empty (). html (‘<div style = “text-align: center; padding-top: 20px; fadeIn (‘fast’)
}, // error when the output of God horse
success: function (a) {
$ (‘# hotposts’). empty (). html (a) // output when the god horse
}
});
return false
};
ajaxs ();
3, in the function.php file to write:
function AjaxLoad () {
if (isset ($ _ GET [‘action’])) {
if ($ _ GET [‘action’] == ‘ajax’) {
echo ‘Oh shit’; / / You can output according to need, such as the output of the latest comments, the latest article, the latest sister what
die;
}
// if ($ _ GET [‘action’] == ‘ajax’) {
/ / If you understand, then this code can also write a number of right?
}
}
add_action (‘init’, ‘AjaxLoad’);
Done successfully.
With the above template, basically the functions to be used can be completed, such as the mouse across: $ (‘# xxx’). Hover (function () {…}, such as click somewhere: $ ( ‘#ooo’). click (function () {…}. Put the last sentence in the js section to the inside to complete the bird. Specifically see the ink theme of the sidebar newcomments and Active Friends part of the effect.