Advertisement
brasofilo

Blogroll Shortcode v2

Oct 6th, 2011
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.60 KB | None | 0 0
  1. <?php
  2. /*
  3.  * WordPress Shortcode
  4.  * Install : Drop in your functions.php, or create a simple plugin (and drop all your functions there)
  5.  * Description : Displays the blogroll of a site
  6.  * Dependencies : Can be used with My-Link-Order plugin, or without it
  7.  * Usage : write the shortcode in any post/page [myblogroll]
  8.  *       : to display only one category use this [myblogroll catslug="blogroll"]
  9.  */
  10. function printLinks( $atts, $content = null ) {
  11.     extract( shortcode_atts( array(
  12.             'catslug' => ''
  13.         ), $atts ) );
  14.     $ritorna = "";
  15.     $taxonomy = 'link_category';
  16.     if (!function_exists('mylinkorder_get_bookmarks')) {
  17.         $args = array('orderby'=>'name','slug'=>$catslug);
  18.     } else {
  19.         $args = array('orderby'=>'order','slug'=>$catslug);
  20.     }
  21.     $terms = get_terms( $taxonomy, $args );
  22.     if ($terms) {
  23.         foreach($terms as $term) {
  24.             if ($term->count > 0 && $term->slug!='uncategorized') {
  25.                 $ritorna .= "<br /><h3>".$term->name."</h3>";
  26.                 if (!function_exists('mylinkorder_get_bookmarks')) {
  27.                     $bookmarks = get_bookmarks( array(
  28.                                     'orderby'        => 'name',
  29.                                     'order'          => 'ASC',
  30.                                     'category_name' => $term->name
  31.                                               ));
  32.                 } else {
  33.                     $bookmarks = mylinkorder_get_bookmarks( array(
  34.                                     'orderby'        => 'order',
  35.                                     'category_name' => $term->name
  36.                                               ));
  37.                 }
  38.                 foreach ( $bookmarks as $bm ) {
  39.                     $ritorna .= sprintf( '<a class="relatedlink" href="%s">%s</a><br />', $bm->link_url, __($bm->link_name) );
  40.                 }
  41.  
  42.             }
  43.         }
  44.     }
  45.     return $ritorna;
  46. }
  47. add_shortcode('myblogroll', 'printLinks');
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement