Support » Plugin: My Link Order » Shortcode for displaying links in a page

  • i just posted part of this code in other threads, but here’s the full version

    what motivated me was that Relevanssi plugin doesn’t search inside the links, and the solution is doing a page with a shortcode, [myblogroll] in this case

    function printLinks( $atts, $content = null ) {
    	$ritorna = "";
    	$taxonomy = 'link_category';
    	if (!function_exists('mylinkorder_get_bookmarks')) {
    		$args = array('orderby'=>'name');
    	} else {
    		$args = array('orderby'=>'order');
    	$terms = get_terms( $taxonomy, $args );
    	if ($terms) {
    		foreach($terms as $term) {
    			if ($term->count > 0 && $term->slug!='uncategorized') {
    				$ritorna .= "<br /><h3>".$term->name."</h3>";
    				if (!function_exists('mylinkorder_get_bookmarks')) {
    					$bookmarks = get_bookmarks( array(
    									'orderby'        => 'name',
    									'order'          => 'ASC',
    									'category_name' => $term->name
    				} else {
    					$bookmarks = mylinkorder_get_bookmarks( array(
    									'orderby'        => 'order',
    									'category_name' => $term->name
    				foreach ( $bookmarks as $bm ) {
    				 	$ritorna .= sprintf( '<a class="relatedlink" href="%s">%s</a><br />', $bm->link_url, __($bm->link_name) );
    	return $ritorna;
    add_shortcode('myblogroll', 'printLinks');

    note that:
    – the code is redundant, in case of deactivation of my-link-order
    – i’m exluding the category ‘uncategorized’ in this example

Viewing 7 replies - 1 through 7 (of 7 total)
  • now in the pastebin, as per forum rules:

    Brasofilo –

    Thank you so much for this! It is exactly what I needed!

    There is just one more thing that would help me out –
    I have three separate pages that will each display only one of the link categories from the my link order plugin, so I am using the function you have provided three times, each with different shortcodes that I will trigger on their respective pages.

    What I need to know is how to either tell this function to only include one specific category, or how to exclude more than one category. I tried this:
    if ($term->count > 0 && $term->slug!='literary,fun-stuff') {
    if ($term->count > 0 && $term->slug!='literary, fun-stuff') {
    if ($term->count > 0 && $term->slug!='literary','fun-stuff') {
    but none seem to work.

    Any help would be very much appreciated!

    hi mattron, I updated the pastebin, now you can use an attribute like this [myblogroll catslug=”blogroll”], to include a specific category using its slug name



    Thank you so much! That’s exactly what I needed! It doesn’t seem to be working right now however, but it is probably something on my end.

    I copied the new code from the pastebin and replaced the old function in the functions.php file, and on my pages put the shortcode, example:
    [myblogroll catslug=”photography”], but still each category shows up on the page. Any thoughts?

    I really appreciate your help!

    sorry mate, line 19 was missing an argument, I modified the pastebin, it should work now

    Thank you so much brother!
    It worked, and it is excellent!

    Thank you, and best wishes!

    all the best

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Shortcode for displaying links in a page’ is closed to new replies.