WordPress.org

Ready to get started?Download WordPress

Forums

random links in sidebar (5 posts)

  1. hristov
    Member
    Posted 8 years ago #

    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.

  2. moshu
    Member
    Posted 8 years ago #

    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.

  3. hristov
    Member
    Posted 8 years ago #

    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.

  4. moshu
    Member
    Posted 8 years ago #

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

  5. hristov
    Member
    Posted 8 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic