Support » Fixing WordPress » How to order links/blogroll

  • Anyone know how to order links in the sidebar in a custom order? I know this has come up before, but all the posts seem to be 3 years old at least.

    Is there an easy way to do it now?

    Many thanks

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter eatanicecream

    (@eatanicecream)

    Thanks – but all I seem to be able to do is change the order they are displayed in in the back end – not on the blog itself. I changed the rating of them, then chose to order by rating, but they still show in alphabetical order in the sidebar.

    If I use different categories and have several link widgets the category heading is displayed which I don’t want.

    Am I being totally thick here? 🙂

    Hi, are you using the links widget to display them in the sidebar? or is it just part of the theme? If the links are being displayed as part of the theme you might need to change some parameters in the code to show them ordered by the rating.

    Let me know if you’re using the widget or not so I can give you a more proper help.

    Best regards =)

    Thread Starter eatanicecream

    (@eatanicecream)

    I’m using the links widget but it’s a custom theme designed from scratch by me. Perhaps I’ve done something wrong with the sidebar?

    This is it:

    <div id="sidebar1">
    
    <div id="sidebarwrapper">
    
    	<ul>
    	<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(1) ) : else : ?>
    
    <div class="widgets">
            <li>
            <h2><?php _e('Categories'); ?></h2>
                <ul>
                <?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>
                </ul>
            </li>
    
    </div><!--End widgets-->
    
            <li>
            <h2><?php _e('Archives'); ?></h2>
                <ul>
                <?php wp_get_archives('type=monthly'); ?>
                </ul>
            </li>
    
    <div class="widgets">
    
            <li>
            <h2><?php _e('Links'); ?></h2>
                <ul>
                 <?php get_links(2, '<li>', '</li>', '', TRUE, 'url', FALSE); ?>
                 </ul>
            </li>
    
    </div><!--End widgets-->
    
    	<?php endif; ?>
    	</ul>
    
    </div>
    </div>

    Thanks!

    Hi eatanicecream!

    Ok let’s see..

    If that’s the exact code in your sidebar.php, then you are not using the Links Widget, you are using php and WP API code to include the links (simulating a widget structure), this is the part of the code that inserts your links:

    <?php get_links(2, '<li>', '</li>', '', TRUE, 'url', FALSE); ?>

    You are sorting your links by the “url” name. You should tell the function to sort your links by “rating” instead:

    <?php get_links(2, '<li>', '</li>', '', TRUE, 'rating', FALSE); ?>

    Then go to your Dashboard and set different ratings for your links, that should work. If you don’t feel like wanting to use the “rating” parameter, you can use the “rel” or “description” doing the same process as I told before.

    Note: get_links is a deprecated function of WP, in the future you should use wp_list_bookmarks.

    Note #2: Updated to WP 3??

    Best Regards, let me know how it goes.

    Thread Starter eatanicecream

    (@eatanicecream)

    Hi, thanks for your suggestions.

    I’ve tried both

    <?php get_links(2, '<li>', '</li>', '', TRUE, 'rating', FALSE); ?>

    and

    <?php wp_list_bookmarks('orderby=rating'); ?>

    but neither makes a difference. Any other suggestions?

    I was using WordPress MU so I’ve been slightly worried about upgrading but have now done so and it went smoothly. Thanks for prompting!

    Did you changed the rating of the links in the dashboard when using the “rating” option?

    Regards.

    Thread Starter eatanicecream

    (@eatanicecream)

    Yeah, I have… Tried change the orderby to id too and that didn’t work either.

    This is what the sidebar looks like now:

    <div id="sidebar1">
    
    <div id="sidebarwrapper">
    
    	<ul>
    	<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(1) ) : else : ?>
    
    <div class="widgets">
            <li>
            <h2><?php _e('Categories'); ?></h2>
                <ul>
                <?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>
                </ul>
            </li>
    
    </div><!--End widgets-->
    
            <li>
            <h2><?php _e('Archives'); ?></h2>
                <ul>
                <?php wp_get_archives('type=monthly'); ?>
                </ul>
            </li>
    
    <div class="widgets">
    
            <li>
            <h2><?php _e('Links'); ?></h2>
                <ul>
                 <?php wp_list_bookmarks('orderby=rating'); ?>
                 </ul>
            </li>
    
    </div><!--End widgets-->
    
    	<?php endif; ?>
    	</ul>
    
    </div>
    </div>

    Ok I think we missed something important, pay attention to this line:

    <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(1) ) : else : ?>

    That means that what’s under that line will be visible only if there are no widgets hooked to the sidebar, so all the changed that we’ve tried before won’t work if you have widgets in your sidebar. Unfortunately the WP native links widget doesn’t allow you to set the “order” in wich the links are displayed.

    Let’s see.. do you have another widgets hooked in the sidebar besides the links widget? If that’s the case.. try this:

    <div id="sidebar1">
    
    <div id="sidebarwrapper">
    
    	<ul>
    	<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar(1) ) : ?>
    
    <div class="widgets">
    
            <li>
            <h2><?php _e('Links'); ?></h2>
                <ul>
                 <?php wp_list_bookmarks('orderby=rating'); ?>
                 </ul>
            </li>
    
    </div><!--End widgets-->
    
    <?php else : ?>
    
    <div class="widgets">
            <li>
            <h2><?php _e('Categories'); ?></h2>
                <ul>
                <?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>
                </ul>
            </li>
    
    </div><!--End widgets-->
    
            <li>
            <h2><?php _e('Archives'); ?></h2>
                <ul>
                <?php wp_get_archives('type=monthly'); ?>
                </ul>
            </li>
    
    	<?php endif; ?>
    	</ul>
    
    </div>
    </div>

    That will show the links widget at the bottom of the sidebar without using the Links Widget (as we are hardcodeing it in the sidebar.php). You will need to delete the widget from the dashboard of course.

    Let me know how it goes and send me a link where I can see your site =)

    Best regards,
    David.

    Thread Starter eatanicecream

    (@eatanicecream)

    Hmm…won’t really work I think. I’m running about 30 blogs off one install. Some users will want to have the links widget, others won’t, so I can’t hardcode it in.

    Surely there must be a way to do it with the widget?

    The blog is http://groups.wdm.org.uk/glasgow. They want to be able to order the ‘Other stuff we like’ links widget.

    Thanks for all your help!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How to order links/blogroll’ is closed to new replies.