Support » Plugin: Random Text » Can I use SOME categories, not ALL or ONE ?

  • Can I start by saying that RANDOM TEXT is probably my number one favourite plugin? It’s so versatile yet so easy to use!

    Now that I’ve done the – much deserved – back slapping, can I ask:

    Is there a simple way to select randomly from SOME categories, as opposed to either ALL or ONE? (Within a template tag / shortcode, not the widget). No doubt I can achieve this with some clever “if” clauses, but is there an easy way?

    Hmmmm … if not, I THINK I’ve just had a thought to answer my own question … set the categories themselves up as a category within RANDOM TEXT then have RANDOM TEXT select the category? (Not sure if that’ll work, but I’m writing it in case others come looking for an answer to the same question.)

    If there’s an easier way, I’d love to know it … if not, I’ll add another post here to say whether or not my thought actually worked!

Viewing 1 replies (of 1 total)
  • Blimey! Easier than I thought! If anyone else comes looking, here’s the php code:

    <?php $mycat = do_shortcode('[randomtext category="funnycat"]'); echo do_shortcode('[randomtext category="'. $mycat . '"]'); ?>

    I’m using do_shortcode because the RANDOM TEXT shortcode is designed to print its output. do_shortcode only prints if you prefix it with echo. The categories that you want to randomly select from can then be added into a new RANDOMTEXT category – in this case ‘funnycat’. RANDOM TEXT will then randomly select from this category, then use that category for the actual RANDOMTEXT output.

    Advantage is that you can add as many categories to select from randomly, and use this with as many ‘groups’ of category as you want … just use different RANDOM TEXT category names.

    This code works directly in posts BUT you need to have a plugin running to allow php in posts. It SHOULD work directly in templates too. Haven’t tried yet, off to do so now. 🙂

    If there’s a still easier way, I’d love to know it. If not, I’ll mark this thread as ‘resolved’, and hope that one day it helps someone else.

Viewing 1 replies (of 1 total)
  • The topic ‘Can I use SOME categories, not ALL or ONE ?’ is closed to new replies.