IPB

Welcome Guest ( Log In | Register )

Movable Type

We're moving to movabletype.org!

At long last, we're moving to forums powered by, well, Movable Type itself. You'll want to bookmark http://forums.movabletype.org/ for future reference, and in the meantime you can view these old forums as a read-only archive of past posts. Thanks for being part of the community!

 
Reply to this topicStart new topic
> Pluggin Request: Random Entries, Is there a plugin for this?
nolageek
post Dec 4 2002, 09:13 AM
Post #1





Group: Members
Posts: 298
Joined: 25-June 02
From: New Orleans
Member No.: 2,996



I posted this in the wrong forum by accident.

I saw a plugin for random comments, but not for random entries.

I'd like to do something like this (in fake-code, since
MTRandomEntries doesn't exsit. (or does it?) smile.gif
CODE
<MTRandomEntries category="Films" num="5">
<a href="<$MTEntryURL$>"><$MTEntryTitle$></a><br><$TEntryExcerpt$>
</MTRandomEntries>


This would basically pick 5 random entries from the category "Film" and let me use the Entry tags within is, like MTEntries would.

Is there anything like this?

Thanks!


--------------------
Go to the top of the page
 
+Quote Post
sunpig
post Dec 4 2002, 10:14 AM
Post #2





Group: Members
Posts: 42
Joined: 11-October 01
From: Edinburgh, Scotland
Member No.: 738



I have been planning to do a RandomEntries tag, but I haven't had the time yet, and I don't think that situation's going to change until at least the new year. sad.gif  (If someone else is working on a RandomEntries tag, please let me know, and I'll be happy to help test it smile.gif )

However, in the meantime, my <$MTRandomLine$> plugin might be able to do the trick.  

What the plugin does, is extract a random line from a text file in your file system, or from a template module, so the code:

CODE
<$MTRandomLine file="/full/path/to/filmentries.html" $>
<$MTRandomLine file="/full/path/to/filmentries.html" $>
<$MTRandomLine file="/full/path/to/filmentries.html" $>
<$MTRandomLine file="/full/path/to/filmentries.html" $>
<$MTRandomLine file="/full/path/to/filmentries.html" $>


will extract and display five random lines from the file filmentries.html.

To generate the file filmentries.html, create it with a new template module.  (Name it something like, "All film entries", and make the Output File "filmentries.html".)  The template code should look something like:

CODE
<MTEntries lastn="100000">
<a href="<$MTEntryURL$>"><$MTEntryTitle$></a><br /><$MTEntryExcerpt$>
</MTEntries>


The key here is to make sure that your Entry Excepts don't contain any line breaks.  So long as they don't, each entry will have its own line in filmentries.html, and the <$MTRandomLine$> tag will extract a whole entry each time.  If they do contain line breaks, then the tag will occasionally grab half-entries, and you'll likely end up with garbled HTML.

Limitations of this method:

1)  The random entries are selected when the template with the <$MTRandomLine$> tag in it is rebuilt.  It doesn't produce a different random selection whenever someone visits the page.  If you want to do that, a search on "random entry" in the forums will give you a number of JavaScript or PHP solutions.

2)  The <$MTRandomLine$> tag doesn't keep track of the selections that previous occurrances of the tag have made.  So if you have five <$MTRandomLine$> tags in a row, probability dictates that sooner or later, all five of them will display the same entry at the same time smile.gif

3)  The line break issue.

I'm using this technique to show a selection of three random blog entries in the sidebar on my own blog.  Let me know if you decide to give it a try smile.gif


--------------------
Legends Of The Sun Pig

"High on hope, he has forgotten what he loved and, instead,
loves the ideal more than the reality, which is the cause
of all the misery that the human species creates for itself."
:: Dean Koontz - Seize the Night ::
Go to the top of the page
 
+Quote Post
girlie
post Dec 4 2002, 05:36 PM
Post #3





Group: Super Administrators
Posts: 15,212
Joined: 8-November 01
From: Plano, Texas
Member No.: 1,274



great timing


--------------------
Go to the top of the page
 
+Quote Post
rayners
post Dec 4 2002, 06:08 PM
Post #4





Group: Members
Posts: 252
Joined: 16-September 02
From: Owings Mills, MD
Member No.: 4,542



This is actually the request that prompted me to write the plugin. smile.gif


--------------------
David Raynes
My Plugin Support Forums
I am just a figment of my own imagination.
Go to the top of the page
 
+Quote Post
girlie
post Dec 4 2002, 06:10 PM
Post #5





Group: Super Administrators
Posts: 15,212
Joined: 8-November 01
From: Plano, Texas
Member No.: 1,274



Hehe, I suspected so.  :)

But wanted a link here for some day down the road when someone needs to find the answer.


--------------------
Go to the top of the page
 
+Quote Post
nolageek
post Dec 4 2002, 07:29 PM
Post #6





Group: Members
Posts: 298
Joined: 25-June 02
From: New Orleans
Member No.: 2,996



This is acting really weird.  Check out my site at NOGLFF.  The different tags are linking to different pages.

Here's the code I used:
CODE
<MTRandomEntries category="Films" lastn="3">
<div class="imageleft"><a href="<$MTEntryLink$>"><img src="<$MTBlogURL$>/images/films/<$MTEntryTitle dirify="1"$>.jpg" border="0" width="150" height="100"><br><$MTEntryTitle$></a></div>
</MTRandomEntries>


As you can see I name images MTEntryTitle.jpg

The REALLY weird thing is that on the schedule page, all the links are wrong as well.  If I change MTRandomEntries to MTEntries everything works fine.

Freaky!

One thing I notice, when clicking around..  the bottom image is always the one that is in the clicked one..  even if it's not the one I click on.  DOes that make sense?


Vincent


--------------------
Go to the top of the page
 
+Quote Post
girlie
post Dec 4 2002, 08:14 PM
Post #7





Group: Super Administrators
Posts: 15,212
Joined: 8-November 01
From: Plano, Texas
Member No.: 1,274



I guess I'm just not understanding what *exactly* is wrong?? The links all appear to be working to me.

"the different tags are linking to different pages"? huh??


--------------------
Go to the top of the page
 
+Quote Post
nolageek
post Dec 4 2002, 09:17 PM
Post #8





Group: Members
Posts: 298
Joined: 25-June 02
From: New Orleans
Member No.: 2,996



It;s very hard to explain, when I use MTRandomEntry in just that one part, it's almost as though my individual archive pages are also randomised....  000354.htm actually contains the information for article number 224 instead of 354.  000224 has the info for 154 (it's randomising EVERYTHING.)
It's working now because Im just using MTEntries.

Vincent


--------------------
Go to the top of the page
 
+Quote Post
staggernation
post Dec 6 2002, 09:17 AM
Post #9





Group: Members
Posts: 548
Joined: 9-July 02
Member No.: 1,291



If you're using MySQL and have a recent enough version, you could do random entries, categories, comments, pings, or authors pretty easily with the SQL Plugin. To get 3 random entries, for example:
CODE
<MTSQLEntries query="SELECT entry_id FROM mt_entry WHERE (entry_blog_id = 1) AND (entry_status = 2) ORDER BY rand() LIMIT 3">
<a href="<MTEntryLink>"><MTEntryTitle></a><br />
</MTSQLEntries>

The ORDER BY rand() won't work with older versions of MySQL, although there may be ways around that...


--------------------
Kevin Shay | staggernation.com
Go to the top of the page
 
+Quote Post
rayners
post Dec 6 2002, 09:37 AM
Post #10





Group: Members
Posts: 252
Joined: 16-September 02
From: Owings Mills, MD
Member No.: 4,542



QUOTE
It;s very hard to explain, when I use MTRandomEntry in just that one part, it's almost as though my individual archive pages are also randomised....  000354.htm actually contains the information for article number 224 instead of 354.  000224 has the info for 154 (it's randomising EVERYTHING.)
It's working now because Im just using MTEntries.

What version of MTRandomEntries are you using?  I just put out a new one this morning.


--------------------
David Raynes
My Plugin Support Forums
I am just a figment of my own imagination.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 11.24.09 - 10:36 PM