chayton Posted April 19, 2010 Share Posted April 19, 2010 I'm a PHP noob but I'm trying to learn - I used to do some Director/lingo coding so I'm not completely moronic, but I'm still getting a grip on PHP syntax and how everything works, so if anyone can give me some help with this, I'd appreciate it. First let me explain what I'm doing - I have a wordpress blog and on my home page I'm displaying a gallery using the "links" section of wordpress and using images for it. I've currently got code like this: <?php $gallery = array( 'category' => 104, 'order' => 'ASC', 'orderby' => 'name', 'categorize' => false, 'title_li' => false, 'before' => false, 'after' => false, 'show_images' => true, 'category_before' => false, 'category_after' => false, ); ?> <?php wp_list_bookmarks($gallery); ?> and it works great, but I'd like to expand it. Right now it takes everything I have in the links and displays them so I have to physically limit the amount of links I have. What I'd like to be able to do is enter all the links, then have the code grab a number (16) entries at random, and display only those - and display them randomly rather than by name. I know it's probably really easy but everything I've tried seems to break it, so I know I'm just not 'getting it' Do I need to get this first array and then use the (rand) function on it? Or can this code be modified to do the rand as is? thanks in advance! Link to comment https://forums.phpfreaks.com/topic/199022-need-some-help-with-rand/ Share on other sites More sharing options...
aeroswat Posted April 19, 2010 Share Posted April 19, 2010 You might be able to replace that 'orderby' => 'name' with 'orderby' => 'RAND()' That MIGHT work but without seeing your code I wouldn't know. Also it would be a very bad idea if the database is somewhat large. Link to comment https://forums.phpfreaks.com/topic/199022-need-some-help-with-rand/#findComment-1044662 Share on other sites More sharing options...
Cagecrawler Posted April 19, 2010 Share Posted April 19, 2010 Wordpress documentation gives rand as an acceptable value for orderby, which will "Display bookmarks in random order". http://codex.wordpress.org/Template_Tags/wp_list_bookmarks Link to comment https://forums.phpfreaks.com/topic/199022-need-some-help-with-rand/#findComment-1044670 Share on other sites More sharing options...
chayton Posted April 19, 2010 Author Share Posted April 19, 2010 Thanks - the rand function works. But how can I make it so it only picks a certain number of the total items? For example in this array there are 50 items - I only want to display 16 randomly chosen items every time. Is that possible? Sorry if I'm missing something obvious.... Link to comment https://forums.phpfreaks.com/topic/199022-need-some-help-with-rand/#findComment-1044772 Share on other sites More sharing options...
chayton Posted April 19, 2010 Author Share Posted April 19, 2010 oh duh....I'm just looking at the parameters and there's one for limit! Let me try that.... Link to comment https://forums.phpfreaks.com/topic/199022-need-some-help-with-rand/#findComment-1044776 Share on other sites More sharing options...
chayton Posted April 19, 2010 Author Share Posted April 19, 2010 Awesome - I set a limit and ordered by rand and it works perfectly! Thanks very much for the help, and especially thanks Cagecrawler for that link! Link to comment https://forums.phpfreaks.com/topic/199022-need-some-help-with-rand/#findComment-1044783 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.