WordPress.org

Support

Support » How-To and Troubleshooting » random links in sidebar

random links in sidebar

  • i’ve checked the forum and the manual and can’t find what should be a simple solution to this problem:

    in my sidebar i’ve used the default code (get_links('-1', etc) to list links. however, as i intend to have a lot of links i want to only display 10. i want these 10 to be randomly selected from all links.

    can anyone suggest how this could be done (with the code if possible)?

    thanks in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Everything is there in the Codex:
    Template_Tags/get_links

    <?php get_links(category, 'before', 'after', 'between', show_images, 'order', show_description, show_rating, limit, show_updated, echo); ?>

    meaning you have to set the 6th parameter to 'rand' and the 9th parameter to 10.
    e.g.
    <ul>
    <?php get_links('-1', '<li>', '</li>', '<br />', FALSE, 'rand', TRUE,
    TRUE, 10, TRUE); ?>
    </ul>

    Change wichever parameter you don’t like.

    excellent, thanks for that… i just didn’t spot it!

    i’ve developed an additional links problem during the day. my ‘links’ in the sidebar is repeating on every ‘page’. its fine when posts are involved, just not for wp pages. can you suggest any solution for this? url’s http://www.heymanchester.com/ (click one of the ‘features’ on the right for the problem pages).

    thanks again.

    I guess you should use some Conditional_Tags and “tell” Wp to not display if is_page (sorry, I am not a coder).

    ah, i sorted it. the theme (‘connections’) came with the links outside sidebar.php for some reason. i removed it from the main template but page.php was of course a separate template. silly design for what is otherwise a great theme.

    thanks for your suggestion again though moshu.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘random links in sidebar’ is closed to new replies.
Skip to toolbar