scriptygoddess

13 Apr, 2002

random blog list

Posted by: Jennifer In: Scripts

So you have a really long list of blogs. But you only want a select few to show up on your main page, because that list is just too long and it overwhelms your site.

Here's how you do it (in php)…

Make your list of blog links – one blog link per line. You can even have little decorative characters around the links… Like, on Christine's blog, she has those little "::" before each link. Just make sure you don't have extra returns in there…

then add this code where you want your random blog links to show up:

<?
$array = file("/path/to/your/file/bloglinks.php");
shuffle($array);
for ($i=0; $i<10; $i++) {
echo $array[$i];
}
?>

This will show 10 random links on your page. Change the "<10" to <20 or <25 or however many you want to show…

assumptions:
1) you've named your file: bloglinks.php
2) you're able to run php scripts on this page

————————————
in case you don't want to read through the comments – I've moved this code into the main post…

If you want to alphabetize that list:

<?
$array = file("/path/to/your/list/of/blogs/bloglinks.php");
shuffle($array);
for ($i=0; $i<10; $i++) {
$miniarray[$i] = $array[$i];
}
sort($miniarray);
for ($i=0; $i<count($miniarray); $i++) {
echo $miniarray[$i];
}
?>

and make your bloglinks file look like this:

<!– A life uncommon –> <a href="etc etc.
<!– Blahblahblog –> <a href="etc. etc.

Additional note: if it seems like you're list is being pulled in completely, and you're on a Mac – there is something about text files edited on a Mac where the "returns" aren't read as "returns" by the server… you might want to try this method:

Between each blog line add "|||" so your list would look like this:
<!– a life uncommon –> <a href="http://a.lifeuncommon.com">a life uncommon</a><br>|||
<!– big pink cookie –> <a href="http://www.bigpinkcookie.com">big pink cookie</a><br>
etc.

Then where you want your list to show up, use this code:
<?
$link_array = file("/path/to/your/list/of/blogs/bloglinks.php");
$link_array2 = implode("", $link_array);
$link_array3 = explode ("|||", $link_array2);
shuffle($link_array3);
for ($i=0; $i<10; $i++) {
$miniarray[$i] = $link_array3[$i];
}
sort($miniarray);
for ($i=0; $i<count($miniarray); $i++) {
echo $miniarray[$i];
}
?>

(change that "10" in the code above to the number of links you want to display)

57 Responses to "random blog list"

1 | Jake

September 24th, 2003 at 12:39 am

Avatar

This script is good. This way you don't have to use blogrolling.
What I am wanting to do with it is have it set up in rows, but the way I do it it puts duplicate urls in. Is there a way to make it so it doesn't take duplicates?

2 | marc

December 1st, 2003 at 11:52 am

Avatar

Thanks! Very cool PHP random list HTML tag generator.

3 | norm

February 22nd, 2004 at 4:42 pm

Avatar

Is it possible to modify this code for it to show the given amount of links for 1 day and not show the same links twice for a given amount of days?

4 | Alberto

February 28th, 2004 at 12:55 am

Avatar

You'd use natecasesort() rahter than sort.
ciao
Alberto
http://www.unitedscripters.com/

5 | michael

April 8th, 2004 at 2:34 am

Avatar

hello Scripty G,

love your script .. just looking now for a way i can offer people the whole list as well as only seven .. if i feed a link via the url .. oo yes it works

michael

6 | Marie

August 21st, 2004 at 12:31 pm

Avatar

Is there a way modify the code to break a long list (30 links, personally) into blocks of five or ten links?

7 | The Weblog @ Betizuka.com » Sucky Blogroll

July 15th, 2007 at 10:55 pm

Avatar

[…] it's becoming an annoyance more than anything else. I'm simply going to use this cool Random Links script created by the goddesses a while back. ¡Abajo […]

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements