Jump to content


These Forums Are Now Read-Only


For TubePress support, please post a question here or open a support ticket and we will be glad to assist.


Photo

orderBy="random" not working [SOLVED]


  • Please log in to reply
12 replies to this topic

#1 lakeebs

lakeebs

    Member

  • Members
  • PipPip
  • 22 posts

Posted 18 May 2012 - 03:17 AM

I currently have the code in my template set up like this:

print TubePressPro::getHtmlForShortcode('mode="playlist" playlistValue="6BD7250ED8CD4FC1" orderBy="random" playerLocation="normal" embeddedHeight="151" embeddedWidth="260" title="false" resultsPerPage="1"');

Ideally, I'd like it to grab a random video from that playlist I listed. However, it always grabs the latest video. Is there something I overlooked?

#2 eric

eric

    Lead Developer

  • TubePress Staff
  • 2787 posts

Posted 18 May 2012 - 12:10 PM

You haven't overlooked anything. You've simply run into a limitation on YouTube's end. From the TubePress docs for orderBy="random":

Will only randomize the order for a single gallery page. e.g. If you have a gallery with a total of 500 videos, with 20 videos per page, only 20 videos at a time will be shuffled.


YouTube unfortunately doesn't provide us with a "true" random capability. So unfortunately until they do there's no workaround that I can think of. If anyone else has a solution, please let us know!

#3 lakeebs

lakeebs

    Member

  • Members
  • PipPip
  • 22 posts

Posted 18 May 2012 - 12:37 PM

Thanks, Eric. I'm not sure if I'm understanding that quote correctly but it would seem likely that if I changed the resultsPerPage to a higher number like 20 or 50 (the limit), and just hid the gallery with CSS leaving only the embedded video, it would show a different video embed each time since the gallery is still being called. Or am I way off?

#4 eric

eric

    Lead Developer

  • TubePress Staff
  • 2787 posts

Posted 21 May 2012 - 08:31 PM

That's right - if you set resultsPerPage to something high and have your page only display only the embedded video player, you can effectively show a random video from the first 50 that the feed returns. You could hide the thumbs with CSS, but I would recommend creating and activating a custom TubePress theme and filling your theme's gallery.tpl.php with these contents:

<div class="tubepress_container" id="tubepress_gallery_<span class="syntaxdefault"><?php echo ${org_tubepress_api_const_template_Variable::GALLERY_ID}; ?>">    <?php echo ${org_tubepress_api_const_template_Variable::PLAYER_HTML}; ?></div></span>
That will prevent the thumbnails from making it into your HTML at all, which should improve your page's performance. But the CSS method will work fine as well - it's whatever is easiest for you.

Let me know if that makes sense or if you have any questions on how to get everything working right. Thanks!

#5 lakeebs

lakeebs

    Member

  • Members
  • PipPip
  • 22 posts

Posted 23 May 2012 - 12:26 PM

Hey Eric,

I tried this but unfortunately it didn't work. The same video keeps being shown in the embed. Here is what I have in my template.

<?php print TubePressPro::getHtmlForShortcode('mode="playlist" playlistValue="6BD7250ED8CD4FC1" orderBy="random" playerLocation="normal" embeddedHeight="151" embeddedWidth="260" title="false" resultsPerPage="50" randomize_thumbnails="true"'); ?>

I temporarily hid the thumbs with CSS just to test it out.

Any idea why it's not working?

#6 eric

eric

    Lead Developer

  • TubePress Staff
  • 2787 posts

Posted 25 May 2012 - 08:48 PM

Try this shortcode instead:

[tubepress mode="playlist" playlistValue="6BD7250ED8CD4FC1" perPageSort="random" playerLocation="normal" embeddedHeight="151" embeddedWidth="260" title="false" resultsPerPage="50" randomize_thumbnails="true"]
Notice that I just changed "orderBy" to "perPageSort". That should correctly sort the page.

#7 lakeebs

lakeebs

    Member

  • Members
  • PipPip
  • 22 posts

Posted 26 May 2012 - 05:22 PM

That didn't work either, unfortunately. Did you test it out and did it work for you?

#8 eric

eric

    Lead Developer

  • TubePress Staff
  • 2787 posts

Posted 26 May 2012 - 11:20 PM

Yes, I tested that shortcode yesterday and got a randomized sort order. Just to sanity check myself, I checked again tonight and am still getting the expected random sort. The first time I loaded the page, the first video was "Best Fails Of The Week 2 March 2012 || YDL". Then after a refresh it was "Best Fails Of The Week 2 February 2012 || YDL". Then "Best Fails Of The Week 2 April 2012 || YDL". etc. etc.

Could you copy/paste the shortcode you have on your page now? I'd like to just make sure that we're testing the exact same thing.

Thanks for your patience in working this out!

#9 lakeebs

lakeebs

    Member

  • Members
  • PipPip
  • 22 posts

Posted 27 May 2012 - 05:47 PM

Sure, here is the exact code I'm using in my index.php template.

<?php print TubePressPro::getHtmlForShortcode('mode="playlist" playlistValue="6BD7250ED8CD4FC1" perPageSort="random" playerLocation="normal" embeddedHeight="151" embeddedWidth="260" title="false" resultsPerPage="50" randomize_thumbnails="true"'); ?>


#10 eric

eric

    Lead Developer

  • TubePress Staff
  • 2787 posts

Posted 29 May 2012 - 10:07 PM

We're definitely using the exact same shortcode, so now I'm stumped as to why it's not randomizing the sort order for you.

A few more questions... Can you confirm that you're running TubePress Pro version 2.4.2? Could you either share a link to your site or post your TubePress debug output? Either one of those would be useful to help reveal what's going on under the hood.

Thanks!

#11 lakeebs

lakeebs

    Member

  • Members
  • PipPip
  • 22 posts

Posted 29 May 2012 - 11:24 PM

Sure, Eric. I've copied and pasted the debug output here: http://pastebin.com/QQ48iKwQ

Please note that there are two instances of TubePress players loading on this one page. The one I'm having trouble with is the second one.

#12 eric

eric

    Lead Developer

  • TubePress Staff
  • 2787 posts

Posted 29 May 2012 - 11:59 PM

Thank you! Figured it out - it's a bug with an easy workaround.

Simply add orderBy="random" to your shortcode:

mode="playlist" playlistValue="6BD7250ED8CD4FC1" perPageSort="random" playerLocation="normal" embeddedHeight="151" embeddedWidth="260" title="false" resultsPerPage="50" randomize_thumbnails="true" orderBy="random"]
This is clearly a bug, as perPageSort shouldn't rely on the setting of "orderBy" as it currently does. I've filed a bug ticket so that this doesn't slip through the cracks. But it's an easy code fix so I should have it sorted out by the next version of TubePress.

In my test environment, I had WordPress setting orderBy to "random" by default, so that explains why I wasn't seeing the issue.

Please give that workaround a try and let us know. Thanks again.

#13 lakeebs

lakeebs

    Member

  • Members
  • PipPip
  • 22 posts

Posted 30 May 2012 - 07:25 PM

woo hoo! thank you!