WordPress Links Manager - Display a random link from a category


/ Published in: PHP
Save to your folder(s)

Sometimes you just want a random link to display and outside of the default format, this works perfectly and removes all default html (list items / headings).


Copy this code and paste it in your HTML
  1. //swap out the category (33) for your own category
  2. $links = wp_list_bookmarks('title_li=&categorize=0&sort_column=menu_order&show_name=1&echo=0&category=33&orderby=rand&limit=1');
  3.  
  4. //create array from string returned by wp_list_bookmarks
  5. $bookmarks = explode('</li>', $links);
  6.  
  7. //print without a link, if you want you could remove strip_tags() to bring the href back.
  8. print '<p>' . strip_tags( $bookmarks[0] ) . '</p>';

URL: http://wordpress.org/support/topic/adding-special-characters-between-bookmark-links-using-wp_list_bookmarks

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.