WordPress custom link sorting and display of items (no plug-ins required) custom links bookmarks

Source: Internet
Author: User

WordPress manages links, which is relatively weak. For example, it cannot be set.Sorting Method, Cannot set the linkNumber of entries displayedAnd so on

WordPress has arrived at version 2.7. The previous plug-ins that manage links are not easy to use. Moreover, if you use a widget that comes with WordPress to display links, the plug-ins will not work too well, after all, resources are consumed. The so-called "do-it-yourself", we will modify the sorting method of WordPress links and the number of links displayed on the homepage, go!

This document uses wordpress2.7 as an example. It applies to WordPress 2.1 + versions.

 

Starting from WordPress 2.1, the function of display link provided by WP is changed to wp_list_bookmarks. in earlier versions, wp_getlinks is used. We will talk about WP of Version 2.1 +.

For how to use wp_list_bookmarks, see wp_codebox. Here I only list the core parameters used in this article.

Orderby: Display the sorting method of the link. The default value is name. to customize the sorting, use this parameter.

Value range:

    • 'Id'-Background ID of the link
    • 'Url'-URL of the link
    • 'Name'-name of the linked website
    • 'Target'-Link Opening Method
    • 'Description'-Link Description
    • 'Owner'-Creator of the link
    • 'Rating'-Classification of links
    • 'Updated'-release time of The Link
    • 'Rel'-Relationship between the link and the website (xfn ).
    • 'Note'-link remarks
    • 'Rss '-link feed address
    • 'Length'-String Length of the link's website name
    • 'Rand'-Random sorting

 

Limit:The number of links displayed. The default value is-1 (all). to limit the number of links displayed, use this parameter.

Order:Sort changes. The default value is ascending ASC. If descending, DESC is used.

With the above Reserve knowledge, we can start to work --"

Modify the link in WordPress's own widgets:

OpenWP-desDirectory, find the display of widgets for widgets. php and Wordpress, which is the responsibility of this file, firstBackupOpen the file and locate it.Function wp_widget_linksThe Code is as follows:

In the above content, there is no such thing as orderby, order, and limit at all, so we use the default values of WP.

Next, we need to modify the above content and add our own custom content. The modified code is as follows:

<? PHP/*** display links widget. ** @ since 2.2.0 ** @ Param array $ ARGs widget arguments. */function wp_widget_links ($ ARGs) {extract ($ ARGs, extr_skip); $ before_widget = preg_replace ('/id = "[^"] * "/', 'id = "% ID" ', $ before_widget); wp_list_bookmarks (apply_filters ('widget _ links_args', array ('title _ before' => $ before_title, 'title _ after' => $ after_title, 'category _ before '=> $ before_widget, 'category _ after' => $ After_widget, 'show _ images' => true, 'class' => 'linkcat components', 'limit '=> 15/* How many display items */, 'orderby' => 'rating'/* sorting field */); echo '<span style = "float: Right; padding-right: 5px "> <a href =" http://www.zu14.cn/links/ "> more links & raquo; </a> </span> ';}?>

As you can see, the modification above only adds two parameter values, limit and orderby, which implement the limit on the number of display items and the custom sorting function, and addsMore linksTo display all, provided that you have publishedLink Page

Modify the link display mode of a topic.

Link Management in a topic, usually the links contained in the topic. for names such as PHP (different theme may be different), find this file, locate the wp_list_bookmarks in it, and add parameters to the function as above. I will not give an example.

Here we provide you with the modified download of Widgets. php, WordPress 2.7

After the download, modify the "more links" url for your own page address and upload it to the WP-topics directory. Back up the original address first.
Widgets. php

Original article: http://www.zu14.cn/2008/12/14/wordpress_custom_link/

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.