Home>Support>Using Post Loop Widget to display a “Post of the Day”

Using Post Loop Widget to display a “Post of the Day”

By Chris Dawson, 3 years ago. Last reply by Alex S, 3 years ago.

hi, i’ve used the Post Loop Widget previously, along with custom templates.
However, I have a case where I want to use the RANDOM ORDER option to display a random post, but in this case it should *stay the same for the entire DAY*, then the next day would be a different one (rather than random on each page load which is easy to achieve).

I understand that i could potentially use RAND($seed) with a date-based seed number to achieve this?
see last item on https://wordpress.org/support/topic/random-order-24/

BUT… the issue is i don’t know WHERE to specify this. best place i guess would be in my theme functions file, or in a custom template that i pull into the Post Loop Widget for this ‘instance’ (editing the actual post loop widget code directly wouldn’t be the best approach, as it’ll obviously get overwritten with updates). But knowing where the Post Loop Widget code/file IS would help me understand it/do initial tests.

If anyone has any suggestions/pointers here that would be very useful. where can i find the Post Loop Widget code?

(I appreciate there may be OTHER approaches to achieving my ‘Post of the Day’ goal, so i’m all ears on that too!). This would also be a useful feature if easy enough to implement for others to use?

thanks,
chris

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 3 years, 11 months ago Chris Dawson

    i’ve now found /plugins/siteorigin-panels/inc/widgets/post-loop.php

    and this code for the ‘orderby’ dropdown options:
    <option value="rand" >

    obviously i don’t want to edit this file directly. any suggestions for adding another dropdown option e.g. “”randomPerDay”” based on rand($seed) . where $seed is something like date(“md”)

  2. 3 years, 11 months ago Chris Dawson

    hmmm… oddly, editing /plugins/siteorigin-panels/inc/widgets/post-loop.php doesn’t seem to effect my Post Loop widget – even if i remove one of the orderby drop down options, it remains in the widget UI, why would that be?
    confused!

  3. 3 years, 11 months ago Chris Dawson

    ok… getting somewhere… within post-loop.php is this nugget…
    // If the Widgets Bundle is installed and the post selector is available, use that.
    // Otherwise revert back to our own form fields.

    so ‘If the Widgets Bundle is installed’ then the orderby dropdown menu within the Post Loop widget query comes from /plugins/so-widgets-bundle/base/inc/fields/posts.class.php
    so i’ll continue with some exploration.

    i’d still like to be able to figure out a method without editing these plugin files, obviously!

  4. 3 years, 11 months ago Alex S
    Hi, I Work Here

    Hi Chris,

    To do this I recommend using the siteorigin_widgets_posts_selector_query filter to manually specify and override the post loop widget query arguments that’s passed to WP_Query. This will allow you to add your random seed to the query and any other adjustments of the query. To store the seed, I would use the Transients API.

    For information on how to make modifications to the SiteOrigin Widgets Bundle widgets, please refer to the developer docs.

    Kind regards,
    Alex

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More