WordPress.org

Ready to get started?Download WordPress

Forums

My Link Order
Shortcode for displaying links in a page (8 posts)

  1. brasofilo
    Member
    Posted 2 years ago #

    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

  2. brasofilo
    Member
    Posted 2 years ago #

    now in the pastebin, as per forum rules: http://pastebin.com/wk0fFFzT

  3. mattron
    Member
    Posted 2 years ago #

    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') {
    and
    if ($term->count > 0 && $term->slug!='literary, fun-stuff') {
    and
    if ($term->count > 0 && $term->slug!='literary','fun-stuff') {
    but none seem to work.

    Any help would be very much appreciated!
    Thanks!

  4. brasofilo
    Member
    Posted 2 years ago #

    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

    cheers

  5. mattron
    Member
    Posted 2 years ago #

    brasofilo,

    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!
    mattron.

  6. brasofilo
    Member
    Posted 2 years ago #

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

  7. mattron
    Member
    Posted 2 years ago #

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

    Thank you, and best wishes!
    mattron.

  8. brasofilo
    Member
    Posted 2 years ago #

    bravo!
    all the best

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic