WordPress.org

Plugin Directory

Changeset 471260


Ignore:
Timestamp:
12/05/11 17:59:16 (6 years ago)
Author:
alekarsovski
Message:

Adding version 1.0.1. Numerous bug fixes, addition of the ability to display all categories (properly and not as a result of a bug) and a few smaller improvements.

Location:
display-links-by-category
Files:
2 edited
3 copied

Legend:

Unmodified
Added
Removed
  • display-links-by-category/tags/1.0.1/display-links-by-category.php

    r467559 r471260  
    33Plugin Name: Display Links by Category 
    44Description: Shortcode plugin for displaying links by category through custom fields. 
    5 Version: 1.0.0 
     5Version: 1.0.1 
    66Author: Aleksandar Arsovski 
    77License: GPL2 
     
    2727add_shortcode( 'links_by_cat', 'dlbc_display_links_function' ); 
    2828 
    29 function dlbc_display_links_function( $attr ) { 
     29 
     30function dlbc_display_links_function( $atts ) { 
    3031 
    3132    // Globalize post data and WP database 
    3233    global $post, $wpdb; 
    33  
    34     // Meta key attribute -- default is diplay_links 
    35     extract( shortcode_atts( array( 'field_id' => 'display_links' ), $attr ) ); 
    3634     
    37     // Get the category name from the custom field 
    38     // True is set as currently the custom field takes only one category at a time 
    39     $category_name = get_post_meta( $post->ID, $field_id, true ); 
    4035     
    41     // Get the category ID from the database by using the category name 
    42     $category_id = $wpdb->get_var( "SELECT term_id FROM $wpdb->terms WHERE name = '$category_name'"); 
     36    // custom field key name -- default value is diplay_links 
     37    $field_atts = shortcode_atts( array( 
     38            'field_id' => 'display_links' 
     39    ), $atts ); 
    4340     
    44     // Generates the code for the category to be displayed 
    45     $list_bookmarks_string = 'category=' . $category_id; 
    4641     
    4742    // The following are additional parameters for display control -- all parameter information taken from http://codex.wordpress.org/Template_Tags/wp_list_bookmarks entry 
     43    $list_bookmarks_atts = shortcode_atts( array( 
     44        'categorize'       => 1, 
     45        'exclude_category' => '', 
     46        'category_name'    => '', 
     47        'category_before'  => '<li id=%id class=%class>', 
     48        'category_after'   => '</li>', 
     49        'class'            => 'linkcat', 
     50        'category_orderby' => 'name', 
     51        'category_order'   => 'ASC', 
     52        'title_li'         => __('Bookmarks'), 
     53        'title_before'     => '<h2>', 
     54        'title_after'      => '</h2>', 
     55        'show_private'     => 0, 
     56        'include'          => '', 
     57        'exclude'          => '', 
     58        'orderby'          => 'name', 
     59        'order'            => 'ASC', 
     60        'limit'            => -1, 
     61        'before'           => '<li>', 
     62        'after'            => '</li>', 
     63        'link_before'      => '', 
     64        'link_after'       => '', 
     65        'between'          => "\n", 
     66        'show_images'      => 1, 
     67        'show_description' => 1, 
     68        'show_name'        => 0, 
     69        'show_rating'      => 0, 
     70        'show_updated'     => 0, 
     71        'hide_invisible'   => 1, 
     72        'echo'             => 0 
     73        ), $atts 
     74    ); 
     75     
     76     
     77    // Check whether display_all was entered / does the user want to display all categories? 
     78    if ( is_array( $atts ) ) 
     79        $display_all = ( in_array( 'display_all', $atts ) ? true : false ); 
    4880     
    49     /*categorize  
    50         (boolean) Bookmarks should be shown within their assigned Categories or not. 
    51         1 (True) - Default 
    52         0 (False) 
    53     */ 
    54     if ( isset( $attr[ 'categorize' ] ) ) 
    55         $list_bookmarks_string .= '&categorize=' . $attr[ 'categorize' ]; 
     81         
     82    // If display all is set no need to check the custom field 
     83    if( !$display_all ) { 
     84     
     85        // Set field_id as variable 
     86        extract( $field_atts ); 
     87         
     88        // Get the category name from the custom field 
     89        $category_name = get_post_meta( $post->ID, $field_id, true ); 
     90     
     91        // Get the category ID from the database by using the category name 
     92        $category_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE name = %s", $category_name ) ); 
     93    } 
    5694     
    5795     
    58     /*exclude_category  
    59         (string) Comma separated list of numeric Category IDs to be excluded from display. 
    60         Defaults to (no categories excluded). 
    61     */ 
    62     if ( isset( $attr[ 'exclude_category' ] ) ) 
    63         $list_bookmarks_string .= '&exclude_category=' . $attr[ 'exclude_category' ]; 
    64          
    65      
    66     /*category_name  
    67         (string) The name of a Category whose bookmarks will be displayed. If none is specified, 
    68         all Categories with bookmarks are shown. Defaults to (all Categories). 
    69     */ 
    70     if ( isset( $attr[ 'category_name' ] ) ) 
    71         $list_bookmarks_string .= '&category_name=' . $attr[ 'category_name' ]; 
     96    if ( isset( $category_id ) ) { 
     97        // Add the selected category to the array 
     98        $list_bookmarks_atts[ 'category' ] = $category_id; 
     99    } 
    72100     
    73101     
    74     /*category_before  
    75         (string) Text to place before each category. Defaults to '<li id="[category id]" class="linkcat">' . 
    76     */ 
    77     if ( isset( $attr[ 'category_before' ] ) ) 
    78         $list_bookmarks_string .= '&category_before=' . $attr[ 'category_before' ]; 
    79          
    80      
    81     /*category_after  
    82         (string) Text to place after each category. Defaults to '</li>' . 
    83     */ 
    84     if ( isset( $attr[ 'category_after' ] ) ) 
    85         $list_bookmarks_string .= '&category_after=' . $attr[ 'category_after' ]; 
     102    // Extract the additional parameters 
     103    extract( $list_bookmarks_atts ); 
    86104     
    87105     
    88     /*class  
    89         (string) The class each category li will have on it. Defaults to 'linkcat'. 
    90         (This parameter was added with Version 2.2) 
    91     */ 
    92     if ( isset( $attr[ 'class' ] ) ) 
    93         $list_bookmarks_string .= '&class=' . $attr[ 'class' ]; 
    94      
    95      
    96     /*category_orderby  
    97         (string) Value to sort Categories on. Valid options: 
    98         'name' - Default 
    99         'id' 
    100         'slug' 
    101         'count' 
    102         'term_group' (not used yet) 
    103     */ 
    104     if ( isset( $attr[ 'category_orderby' ] ) ) 
    105         $list_bookmarks_string .= '&category_orderby=' . $attr[ 'category_orderby' ]; 
    106          
    107          
    108     /*category_order  
    109         (string) Sort order, ascending or descending for the category_orderby parameter. Valid values: 
    110         ASC - Default 
    111         DESC 
    112     */ 
    113     if ( isset( $attr[ 'category_order' ] ) ) 
    114         $list_bookmarks_string .= '&category_order=' . $attr[ 'category_order' ]; 
    115      
    116      
    117     /*title_li  
    118         (string) Text for the heading of the links list. Defaults to '__('Bookmarks')', which displays 
    119         "Bookmarks" (the __('') is used for localization purposes). Only used when categorize are set 
    120         to 0 [false] (else the category names will be used instead). If 'title_li' is set to null (0) value, 
    121         no heading is displayed, and the list will not be wrapped with <ul>, </ul> tags (be sure to pass the 
    122         categorize option to 0 [false] to this option takes effect). 
    123     */ 
    124     if ( isset( $attr[ 'title_li' ] ) ) 
    125         $list_bookmarks_string .= '&title_li=' . $attr[ 'title_li' ]; 
    126      
    127      
    128     /*title_before  
    129         (string) Text to place before each Category description if 'categorize' is 1 [true], or text defined 
    130         in "title_li" if 'categorize' is 0 [false]. Defaults to '<h2>'. 
    131     */ 
    132     if ( isset( $attr[ 'title_before' ] ) ) 
    133         $list_bookmarks_string .= '&title_before=' . $attr[ 'title_before' ]; 
    134      
    135      
    136     /*title_after 
    137         (string) Text to place after each Category description if 'categorize' is 1 [true], or text defined 
    138         in "title_li" if 'categorize' is 0 [false]. Defaults to '</h2>'. 
    139     */ 
    140     if ( isset( $attr[ 'title_after' ] ) ) 
    141         $list_bookmarks_string .= '&title_after=' . $attr[ 'title_after' ]; 
    142      
    143      
    144     /*show_private  
    145         (boolean) Should a Category be displayed even if the Category is considered private. Ignore the admin 
    146         setting and show private Categories (TRUE) or do NOT show private Categories (FALSE). 
    147         1 (True) 
    148         0 (False) - Default 
    149     */ 
    150     if ( isset( $attr[ 'show_private' ] ) ) 
    151         $list_bookmarks_string .= '&show_private=' . $attr[ 'show_private' ]; 
    152      
    153      
    154     /*include  
    155         (string) Comma separated list of numeric bookmark IDs to include in the output. For example, 
    156         'include=1,3,6' means to return or echo bookmark IDs 1, 3, and 6. If the include string is used, 
    157         the category, category_name, and exclude parameters are ignored. Defaults to (all Bookmarks). 
    158     */ 
    159     if ( isset( $attr[ 'include' ] ) ) 
    160         $list_bookmarks_string .= '&include=' . $attr[ 'include' ]; 
    161      
    162      
    163     /*exclude  
    164         (string) Comma separated list of numeric bookmark IDs to exclude. For example, 'exclude=4,12' 
    165         means that bookmark IDs 4 and 12 will NOT be returned or echoed. Defaults to (exclude nothing). 
    166     */ 
    167     if ( isset( $attr[ 'exclude' ] ) ) 
    168         $list_bookmarks_string .= '&exclude=' . $attr[ 'exclude' ]; 
    169      
    170      
    171     /*orderby  
    172         (string) Value to sort bookmarks on. This can be a COMMA separated list of values. Defaults 
    173         to 'name' unless you pass the value of '' (empty), in which case it sets to 'id'. Valid options: 
    174         'id' (use 'link_id' with WP 3.2 and later) 
    175         'url' 
    176         'name' - Default 
    177         'target' 
    178         'description' 
    179         'owner' - User who added bookmark through bookmarks Manager. 
    180         'rating' 
    181         'updated' Note: the link_updated field does not track local modifications. It tracks when 
    182             whatever the link points to is updated via remote requests to pingomatic. 
    183         'rel' - bookmark relationship (XFN). 
    184         'notes' 
    185         'rss' 
    186         'length' - The length of the bookmark name, shortest to longest. 
    187         'rand' - Display bookmarks in random order. 
    188     */ 
    189     if ( isset( $attr[ 'orderby' ] ) ) 
    190         $list_bookmarks_string .= '&orderby=' . $attr[ 'orderby' ]; 
    191      
    192      
    193     /*order  
    194         (string) Bookmarks display sorting order, ascending or descending as defined in the 'orderby' parameter. Valid values: 
    195         ASC - Default 
    196         DESC 
    197     */ 
    198     if ( isset( $attr[ 'order' ] ) ) 
    199         $list_bookmarks_string .= '&order=' . $attr[ 'order' ]; 
    200      
    201      
    202     /*limit  
    203         (integer) Maximum number of bookmarks to display. Default is -1 (all bookmarks). 
    204     */ 
    205     if ( isset( $attr[ 'limit' ] ) ) 
    206         $list_bookmarks_string .= '&limit=' . $attr[ 'limit' ]; 
    207      
    208      
    209     /*before  
    210         (string) Text to place before each bookmark. Defaults to '<li>'. 
    211     */ 
    212     if ( isset( $attr[ 'before' ] ) ) 
    213         $list_bookmarks_string .= '&before=' . $attr[ 'before' ]; 
    214      
    215      
    216     /*after  
    217         (string) Text to place after each bookmark. Defaults to '</li>'. 
    218     */ 
    219     if ( isset( $attr[ 'after' ] ) ) 
    220         $list_bookmarks_string .= '&after=' . $attr[ 'after' ]; 
    221      
    222      
    223     /*link_before  
    224         (string) Text to place before the text of each bookmark, inside the hyperlink code. There is no 
    225         set default. (This parameter was added with Version 2.7) 
    226     */ 
    227     if ( isset( $attr[ 'link_before' ] ) ) 
    228         $list_bookmarks_string .= '&link_before=' . $attr[ 'link_before' ]; 
    229      
    230      
    231     /*link_after  
    232         (string) Text to place after the text of each bookmark. There is no set default. 
    233         (This parameter was added with Version 2.7) 
    234     */ 
    235     if ( isset( $attr[ 'link_after' ] ) ) 
    236         $list_bookmarks_string .= '&link_after=' . $attr[ 'link_after' ]; 
    237      
    238      
    239     /*between  
    240         (string) Text to place between each bookmark/image and its description. Defaults to '\n' (newline). 
    241     */ 
    242     if ( isset( $attr[ 'between' ] ) ) 
    243         $list_bookmarks_string .= '&between=' . $attr[ 'between' ]; 
    244      
    245      
    246     /*show_images  
    247         (boolean) Should images for bookmarks be shown (TRUE) or not (FALSE). 
    248         1 (True) - Default 
    249         0 (False) 
    250     */ 
    251     if ( isset( $attr[ 'show_images' ] ) ) 
    252         $list_bookmarks_string .= '&show_images=' . $attr[ 'show_images' ]; 
    253      
    254      
    255     /*show_description  
    256         (boolean) Should the description be displayed (TRUE) or not (FALSE). Valid when show_images is FALSE, or an image is not defined. 
    257         1 (True) 
    258         0 (False) - Default 
    259     */ 
    260     if ( isset( $attr[ 'show_description' ] ) ) 
    261         $list_bookmarks_string .= '&show_description=' . $attr[ 'show_description' ]; 
    262      
    263      
    264     /*show_name  
    265         (boolean) Displays the text of a link when (TRUE). Works when show_images is TRUE. (This parameter was added with Version 2.7) 
    266         1 (True) 
    267         0 (False) - Default 
    268     */ 
    269     if ( isset( $attr[ 'show_name' ] ) ) 
    270         $list_bookmarks_string .= '&show_name=' . $attr[ 'show_name' ]; 
    271      
    272      
    273     /*show_rating  
    274         (boolean) Should rating stars/characters be displayed (TRUE) or not (FALSE). 
    275         1 (True) 
    276         0 (False) - Default 
    277     */ 
    278     if ( isset( $attr[ 'show_rating' ] ) ) 
    279         $list_bookmarks_string .= '&show_rating=' . $attr[ 'show_rating' ]; 
    280      
    281      
    282     /*show_updated  
    283         (boolean) Should the last updated timestamp be displayed (TRUE) or not (FALSE). Note that link_updated does not track local modifications. It tracks when whatever the link points to is updated via remote requests to pingomatic. 
    284         1 (True) 
    285         0 (False) - Default 
    286     */ 
    287     if ( isset( $attr[ 'show_updated' ] ) ) 
    288         $list_bookmarks_string .= '&show_updated=' . $attr[ 'show_updated' ]; 
    289      
    290      
    291     /*hide_invisible  
    292         (boolean) Should bookmark be displayed even if it's Visible setting is No. Abides by admin setting (TRUE) or does no abide by admin setting (FALSE). 
    293         1 (True) - Default 
    294         0 (False) 
    295     */ 
    296     if ( isset( $attr[ 'hide_invisible' ] ) ) 
    297         $list_bookmarks_string .= '&hide_invisible=' . $attr[ 'hide_invisible' ]; 
    298      
    299      
    300     /*echo  
    301         (boolean) Display bookmarks (TRUE) or return them for use by PHP (FALSE). 
    302         1 (True) - Default 
    303         0 (False) 
    304     */ 
    305     if ( isset( $attr[ 'echo' ] ) ) 
    306         $list_bookmarks_string .= '&link_after=' . $attr[ 'echo' ]; 
    307      
    308      
    309     // Call built-in display links function with all defined parameters from above 
    310     wp_list_bookmarks( $list_bookmarks_string ); 
    311      
     106    // Check whether to display all categories 
     107    if ( $display_all ) { 
     108        // Call built-in display links function to display all links 
     109        return wp_list_bookmarks( $list_bookmarks_atts ); 
     110    } 
     111    // If not displaying all categories 
     112    else { 
     113        // Check whether it's an archive page 
     114        if ( is_archive() ) { 
     115            // If category_name parameter was passed through shortcode, display that link category on archive page 
     116            if ( !empty( $category_name ) ) 
     117                return wp_list_bookmarks( $list_bookmarks_atts ); 
     118        } 
     119        // If not archive page 
     120        else { 
     121            // Check if there's a valid selected category in custom fields on page/post 
     122            if ( isset( $category_id ) || !empty( $category_name ) ) { 
     123                // Call built-in display links function to display selected category 
     124                return wp_list_bookmarks( $list_bookmarks_atts ); 
     125            } 
     126        } 
     127    } 
    312128} 
  • display-links-by-category/tags/1.0.1/readme.txt

    r467559 r471260  
    11=== Plugin Name === 
    2 Contributors: alekarsovski, ubcdev, ctlt-dev 
    3 Tags: links, shortcode, blogroll, bookmarks, custom fields 
     2Contributors: alekarsovski, enej, ubcdev, ctlt-dev 
     3Tags: links, display links, shortcode, blogroll, bookmarks, custom fields 
    44Requires at least: 3.2.1 
    55Tested up to: 3.2.1 
    6 Stable tag: 1.0.0 
     6Stable tag: 1.0.1 
    77 
    88A simple shortcode plugin for displaying links by category through custom fields. 
     
    3030<code>[links_by_cat orderby="rating"]</code> -- This is an example using the orderby parameter from the list. The links will now be ordered by their rating. 
    3131 
     32= Added in 1.0.1: = 
     33The ability to display all categories has been added to the shortcode. Simply add: 
     34<code>[links_by_cat display_all]</code> 
     35 
     36Many bug fixes have also been introduced in version 1.0.1 as well, so please upgrade. 
     37 
     38 
    3239Currently, only one category is supported per Custom Field entry; however, I am looking to update the plugin soon so that it supports multiple categories. 
    3340 
     
    40471. Add new custom fields where needed (full details in "Description" tab) 
    41481. Use the shortcode in any page, post or widget area where you wish your links to appear 
     49 
     50== Changelog == 
     51 
     52= 1.0.1 = 
     53* Addded the option to choose to display all categories 
     54* Bug fixes (ex: if category name is wrong, all categories used to display - now, none are displayed) 
     55 
     56== Upgrade Notice == 
     57 
     58= 1.0.1 = 
     59Several bug fixes and the addition for a display all categories option. Check [plugin page](http://wordpress.org/extend/plugins/display-links-by-category/) for more details. 
  • display-links-by-category/trunk/display-links-by-category.php

    r467559 r471260  
    33Plugin Name: Display Links by Category 
    44Description: Shortcode plugin for displaying links by category through custom fields. 
    5 Version: 1.0.0 
     5Version: 1.0.1 
    66Author: Aleksandar Arsovski 
    77License: GPL2 
     
    2727add_shortcode( 'links_by_cat', 'dlbc_display_links_function' ); 
    2828 
    29 function dlbc_display_links_function( $attr ) { 
     29 
     30function dlbc_display_links_function( $atts ) { 
    3031 
    3132    // Globalize post data and WP database 
    3233    global $post, $wpdb; 
    33  
    34     // Meta key attribute -- default is diplay_links 
    35     extract( shortcode_atts( array( 'field_id' => 'display_links' ), $attr ) ); 
    3634     
    37     // Get the category name from the custom field 
    38     // True is set as currently the custom field takes only one category at a time 
    39     $category_name = get_post_meta( $post->ID, $field_id, true ); 
    4035     
    41     // Get the category ID from the database by using the category name 
    42     $category_id = $wpdb->get_var( "SELECT term_id FROM $wpdb->terms WHERE name = '$category_name'"); 
     36    // custom field key name -- default value is diplay_links 
     37    $field_atts = shortcode_atts( array( 
     38            'field_id' => 'display_links' 
     39    ), $atts ); 
    4340     
    44     // Generates the code for the category to be displayed 
    45     $list_bookmarks_string = 'category=' . $category_id; 
    4641     
    4742    // The following are additional parameters for display control -- all parameter information taken from http://codex.wordpress.org/Template_Tags/wp_list_bookmarks entry 
     43    $list_bookmarks_atts = shortcode_atts( array( 
     44        'categorize'       => 1, 
     45        'exclude_category' => '', 
     46        'category_name'    => '', 
     47        'category_before'  => '<li id=%id class=%class>', 
     48        'category_after'   => '</li>', 
     49        'class'            => 'linkcat', 
     50        'category_orderby' => 'name', 
     51        'category_order'   => 'ASC', 
     52        'title_li'         => __('Bookmarks'), 
     53        'title_before'     => '<h2>', 
     54        'title_after'      => '</h2>', 
     55        'show_private'     => 0, 
     56        'include'          => '', 
     57        'exclude'          => '', 
     58        'orderby'          => 'name', 
     59        'order'            => 'ASC', 
     60        'limit'            => -1, 
     61        'before'           => '<li>', 
     62        'after'            => '</li>', 
     63        'link_before'      => '', 
     64        'link_after'       => '', 
     65        'between'          => "\n", 
     66        'show_images'      => 1, 
     67        'show_description' => 1, 
     68        'show_name'        => 0, 
     69        'show_rating'      => 0, 
     70        'show_updated'     => 0, 
     71        'hide_invisible'   => 1, 
     72        'echo'             => 0 
     73        ), $atts 
     74    ); 
     75     
     76     
     77    // Check whether display_all was entered / does the user want to display all categories? 
     78    if ( is_array( $atts ) ) 
     79        $display_all = ( in_array( 'display_all', $atts ) ? true : false ); 
    4880     
    49     /*categorize  
    50         (boolean) Bookmarks should be shown within their assigned Categories or not. 
    51         1 (True) - Default 
    52         0 (False) 
    53     */ 
    54     if ( isset( $attr[ 'categorize' ] ) ) 
    55         $list_bookmarks_string .= '&categorize=' . $attr[ 'categorize' ]; 
     81         
     82    // If display all is set no need to check the custom field 
     83    if( !$display_all ) { 
     84     
     85        // Set field_id as variable 
     86        extract( $field_atts ); 
     87         
     88        // Get the category name from the custom field 
     89        $category_name = get_post_meta( $post->ID, $field_id, true ); 
     90     
     91        // Get the category ID from the database by using the category name 
     92        $category_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE name = %s", $category_name ) ); 
     93    } 
    5694     
    5795     
    58     /*exclude_category  
    59         (string) Comma separated list of numeric Category IDs to be excluded from display. 
    60         Defaults to (no categories excluded). 
    61     */ 
    62     if ( isset( $attr[ 'exclude_category' ] ) ) 
    63         $list_bookmarks_string .= '&exclude_category=' . $attr[ 'exclude_category' ]; 
    64          
    65      
    66     /*category_name  
    67         (string) The name of a Category whose bookmarks will be displayed. If none is specified, 
    68         all Categories with bookmarks are shown. Defaults to (all Categories). 
    69     */ 
    70     if ( isset( $attr[ 'category_name' ] ) ) 
    71         $list_bookmarks_string .= '&category_name=' . $attr[ 'category_name' ]; 
     96    if ( isset( $category_id ) ) { 
     97        // Add the selected category to the array 
     98        $list_bookmarks_atts[ 'category' ] = $category_id; 
     99    } 
    72100     
    73101     
    74     /*category_before  
    75         (string) Text to place before each category. Defaults to '<li id="[category id]" class="linkcat">' . 
    76     */ 
    77     if ( isset( $attr[ 'category_before' ] ) ) 
    78         $list_bookmarks_string .= '&category_before=' . $attr[ 'category_before' ]; 
    79          
    80      
    81     /*category_after  
    82         (string) Text to place after each category. Defaults to '</li>' . 
    83     */ 
    84     if ( isset( $attr[ 'category_after' ] ) ) 
    85         $list_bookmarks_string .= '&category_after=' . $attr[ 'category_after' ]; 
     102    // Extract the additional parameters 
     103    extract( $list_bookmarks_atts ); 
    86104     
    87105     
    88     /*class  
    89         (string) The class each category li will have on it. Defaults to 'linkcat'. 
    90         (This parameter was added with Version 2.2) 
    91     */ 
    92     if ( isset( $attr[ 'class' ] ) ) 
    93         $list_bookmarks_string .= '&class=' . $attr[ 'class' ]; 
    94      
    95      
    96     /*category_orderby  
    97         (string) Value to sort Categories on. Valid options: 
    98         'name' - Default 
    99         'id' 
    100         'slug' 
    101         'count' 
    102         'term_group' (not used yet) 
    103     */ 
    104     if ( isset( $attr[ 'category_orderby' ] ) ) 
    105         $list_bookmarks_string .= '&category_orderby=' . $attr[ 'category_orderby' ]; 
    106          
    107          
    108     /*category_order  
    109         (string) Sort order, ascending or descending for the category_orderby parameter. Valid values: 
    110         ASC - Default 
    111         DESC 
    112     */ 
    113     if ( isset( $attr[ 'category_order' ] ) ) 
    114         $list_bookmarks_string .= '&category_order=' . $attr[ 'category_order' ]; 
    115      
    116      
    117     /*title_li  
    118         (string) Text for the heading of the links list. Defaults to '__('Bookmarks')', which displays 
    119         "Bookmarks" (the __('') is used for localization purposes). Only used when categorize are set 
    120         to 0 [false] (else the category names will be used instead). If 'title_li' is set to null (0) value, 
    121         no heading is displayed, and the list will not be wrapped with <ul>, </ul> tags (be sure to pass the 
    122         categorize option to 0 [false] to this option takes effect). 
    123     */ 
    124     if ( isset( $attr[ 'title_li' ] ) ) 
    125         $list_bookmarks_string .= '&title_li=' . $attr[ 'title_li' ]; 
    126      
    127      
    128     /*title_before  
    129         (string) Text to place before each Category description if 'categorize' is 1 [true], or text defined 
    130         in "title_li" if 'categorize' is 0 [false]. Defaults to '<h2>'. 
    131     */ 
    132     if ( isset( $attr[ 'title_before' ] ) ) 
    133         $list_bookmarks_string .= '&title_before=' . $attr[ 'title_before' ]; 
    134      
    135      
    136     /*title_after 
    137         (string) Text to place after each Category description if 'categorize' is 1 [true], or text defined 
    138         in "title_li" if 'categorize' is 0 [false]. Defaults to '</h2>'. 
    139     */ 
    140     if ( isset( $attr[ 'title_after' ] ) ) 
    141         $list_bookmarks_string .= '&title_after=' . $attr[ 'title_after' ]; 
    142      
    143      
    144     /*show_private  
    145         (boolean) Should a Category be displayed even if the Category is considered private. Ignore the admin 
    146         setting and show private Categories (TRUE) or do NOT show private Categories (FALSE). 
    147         1 (True) 
    148         0 (False) - Default 
    149     */ 
    150     if ( isset( $attr[ 'show_private' ] ) ) 
    151         $list_bookmarks_string .= '&show_private=' . $attr[ 'show_private' ]; 
    152      
    153      
    154     /*include  
    155         (string) Comma separated list of numeric bookmark IDs to include in the output. For example, 
    156         'include=1,3,6' means to return or echo bookmark IDs 1, 3, and 6. If the include string is used, 
    157         the category, category_name, and exclude parameters are ignored. Defaults to (all Bookmarks). 
    158     */ 
    159     if ( isset( $attr[ 'include' ] ) ) 
    160         $list_bookmarks_string .= '&include=' . $attr[ 'include' ]; 
    161      
    162      
    163     /*exclude  
    164         (string) Comma separated list of numeric bookmark IDs to exclude. For example, 'exclude=4,12' 
    165         means that bookmark IDs 4 and 12 will NOT be returned or echoed. Defaults to (exclude nothing). 
    166     */ 
    167     if ( isset( $attr[ 'exclude' ] ) ) 
    168         $list_bookmarks_string .= '&exclude=' . $attr[ 'exclude' ]; 
    169      
    170      
    171     /*orderby  
    172         (string) Value to sort bookmarks on. This can be a COMMA separated list of values. Defaults 
    173         to 'name' unless you pass the value of '' (empty), in which case it sets to 'id'. Valid options: 
    174         'id' (use 'link_id' with WP 3.2 and later) 
    175         'url' 
    176         'name' - Default 
    177         'target' 
    178         'description' 
    179         'owner' - User who added bookmark through bookmarks Manager. 
    180         'rating' 
    181         'updated' Note: the link_updated field does not track local modifications. It tracks when 
    182             whatever the link points to is updated via remote requests to pingomatic. 
    183         'rel' - bookmark relationship (XFN). 
    184         'notes' 
    185         'rss' 
    186         'length' - The length of the bookmark name, shortest to longest. 
    187         'rand' - Display bookmarks in random order. 
    188     */ 
    189     if ( isset( $attr[ 'orderby' ] ) ) 
    190         $list_bookmarks_string .= '&orderby=' . $attr[ 'orderby' ]; 
    191      
    192      
    193     /*order  
    194         (string) Bookmarks display sorting order, ascending or descending as defined in the 'orderby' parameter. Valid values: 
    195         ASC - Default 
    196         DESC 
    197     */ 
    198     if ( isset( $attr[ 'order' ] ) ) 
    199         $list_bookmarks_string .= '&order=' . $attr[ 'order' ]; 
    200      
    201      
    202     /*limit  
    203         (integer) Maximum number of bookmarks to display. Default is -1 (all bookmarks). 
    204     */ 
    205     if ( isset( $attr[ 'limit' ] ) ) 
    206         $list_bookmarks_string .= '&limit=' . $attr[ 'limit' ]; 
    207      
    208      
    209     /*before  
    210         (string) Text to place before each bookmark. Defaults to '<li>'. 
    211     */ 
    212     if ( isset( $attr[ 'before' ] ) ) 
    213         $list_bookmarks_string .= '&before=' . $attr[ 'before' ]; 
    214      
    215      
    216     /*after  
    217         (string) Text to place after each bookmark. Defaults to '</li>'. 
    218     */ 
    219     if ( isset( $attr[ 'after' ] ) ) 
    220         $list_bookmarks_string .= '&after=' . $attr[ 'after' ]; 
    221      
    222      
    223     /*link_before  
    224         (string) Text to place before the text of each bookmark, inside the hyperlink code. There is no 
    225         set default. (This parameter was added with Version 2.7) 
    226     */ 
    227     if ( isset( $attr[ 'link_before' ] ) ) 
    228         $list_bookmarks_string .= '&link_before=' . $attr[ 'link_before' ]; 
    229      
    230      
    231     /*link_after  
    232         (string) Text to place after the text of each bookmark. There is no set default. 
    233         (This parameter was added with Version 2.7) 
    234     */ 
    235     if ( isset( $attr[ 'link_after' ] ) ) 
    236         $list_bookmarks_string .= '&link_after=' . $attr[ 'link_after' ]; 
    237      
    238      
    239     /*between  
    240         (string) Text to place between each bookmark/image and its description. Defaults to '\n' (newline). 
    241     */ 
    242     if ( isset( $attr[ 'between' ] ) ) 
    243         $list_bookmarks_string .= '&between=' . $attr[ 'between' ]; 
    244      
    245      
    246     /*show_images  
    247         (boolean) Should images for bookmarks be shown (TRUE) or not (FALSE). 
    248         1 (True) - Default 
    249         0 (False) 
    250     */ 
    251     if ( isset( $attr[ 'show_images' ] ) ) 
    252         $list_bookmarks_string .= '&show_images=' . $attr[ 'show_images' ]; 
    253      
    254      
    255     /*show_description  
    256         (boolean) Should the description be displayed (TRUE) or not (FALSE). Valid when show_images is FALSE, or an image is not defined. 
    257         1 (True) 
    258         0 (False) - Default 
    259     */ 
    260     if ( isset( $attr[ 'show_description' ] ) ) 
    261         $list_bookmarks_string .= '&show_description=' . $attr[ 'show_description' ]; 
    262      
    263      
    264     /*show_name  
    265         (boolean) Displays the text of a link when (TRUE). Works when show_images is TRUE. (This parameter was added with Version 2.7) 
    266         1 (True) 
    267         0 (False) - Default 
    268     */ 
    269     if ( isset( $attr[ 'show_name' ] ) ) 
    270         $list_bookmarks_string .= '&show_name=' . $attr[ 'show_name' ]; 
    271      
    272      
    273     /*show_rating  
    274         (boolean) Should rating stars/characters be displayed (TRUE) or not (FALSE). 
    275         1 (True) 
    276         0 (False) - Default 
    277     */ 
    278     if ( isset( $attr[ 'show_rating' ] ) ) 
    279         $list_bookmarks_string .= '&show_rating=' . $attr[ 'show_rating' ]; 
    280      
    281      
    282     /*show_updated  
    283         (boolean) Should the last updated timestamp be displayed (TRUE) or not (FALSE). Note that link_updated does not track local modifications. It tracks when whatever the link points to is updated via remote requests to pingomatic. 
    284         1 (True) 
    285         0 (False) - Default 
    286     */ 
    287     if ( isset( $attr[ 'show_updated' ] ) ) 
    288         $list_bookmarks_string .= '&show_updated=' . $attr[ 'show_updated' ]; 
    289      
    290      
    291     /*hide_invisible  
    292         (boolean) Should bookmark be displayed even if it's Visible setting is No. Abides by admin setting (TRUE) or does no abide by admin setting (FALSE). 
    293         1 (True) - Default 
    294         0 (False) 
    295     */ 
    296     if ( isset( $attr[ 'hide_invisible' ] ) ) 
    297         $list_bookmarks_string .= '&hide_invisible=' . $attr[ 'hide_invisible' ]; 
    298      
    299      
    300     /*echo  
    301         (boolean) Display bookmarks (TRUE) or return them for use by PHP (FALSE). 
    302         1 (True) - Default 
    303         0 (False) 
    304     */ 
    305     if ( isset( $attr[ 'echo' ] ) ) 
    306         $list_bookmarks_string .= '&link_after=' . $attr[ 'echo' ]; 
    307      
    308      
    309     // Call built-in display links function with all defined parameters from above 
    310     wp_list_bookmarks( $list_bookmarks_string ); 
    311      
     106    // Check whether to display all categories 
     107    if ( $display_all ) { 
     108        // Call built-in display links function to display all links 
     109        return wp_list_bookmarks( $list_bookmarks_atts ); 
     110    } 
     111    // If not displaying all categories 
     112    else { 
     113        // Check whether it's an archive page 
     114        if ( is_archive() ) { 
     115            // If category_name parameter was passed through shortcode, display that link category on archive page 
     116            if ( !empty( $category_name ) ) 
     117                return wp_list_bookmarks( $list_bookmarks_atts ); 
     118        } 
     119        // If not archive page 
     120        else { 
     121            // Check if there's a valid selected category in custom fields on page/post 
     122            if ( isset( $category_id ) || !empty( $category_name ) ) { 
     123                // Call built-in display links function to display selected category 
     124                return wp_list_bookmarks( $list_bookmarks_atts ); 
     125            } 
     126        } 
     127    } 
    312128} 
  • display-links-by-category/trunk/readme.txt

    r467559 r471260  
    11=== Plugin Name === 
    2 Contributors: alekarsovski, ubcdev, ctlt-dev 
    3 Tags: links, shortcode, blogroll, bookmarks, custom fields 
     2Contributors: alekarsovski, enej, ubcdev, ctlt-dev 
     3Tags: links, display links, shortcode, blogroll, bookmarks, custom fields 
    44Requires at least: 3.2.1 
    55Tested up to: 3.2.1 
    6 Stable tag: 1.0.0 
     6Stable tag: 1.0.1 
    77 
    88A simple shortcode plugin for displaying links by category through custom fields. 
     
    3030<code>[links_by_cat orderby="rating"]</code> -- This is an example using the orderby parameter from the list. The links will now be ordered by their rating. 
    3131 
     32= Added in 1.0.1: = 
     33The ability to display all categories has been added to the shortcode. Simply add: 
     34<code>[links_by_cat display_all]</code> 
     35 
     36Many bug fixes have also been introduced in version 1.0.1 as well, so please upgrade. 
     37 
     38 
    3239Currently, only one category is supported per Custom Field entry; however, I am looking to update the plugin soon so that it supports multiple categories. 
    3340 
     
    40471. Add new custom fields where needed (full details in "Description" tab) 
    41481. Use the shortcode in any page, post or widget area where you wish your links to appear 
     49 
     50== Changelog == 
     51 
     52= 1.0.1 = 
     53* Addded the option to choose to display all categories 
     54* Bug fixes (ex: if category name is wrong, all categories used to display - now, none are displayed) 
     55 
     56== Upgrade Notice == 
     57 
     58= 1.0.1 = 
     59Several bug fixes and the addition for a display all categories option. Check [plugin page](http://wordpress.org/extend/plugins/display-links-by-category/) for more details. 
Note: See TracChangeset for help on using the changeset viewer.