We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36786 ☆ A M B ☆
    • 209 Posts
    So I'm trying to have the "Featured Video" module on our page's sidebar show a different video (each a resource) every day. It could be in order or random, either would be fine. Is there a way to do this?

    This question has been answered by opengeek. See the first response.

      Ben Morrison
      Hacking templates to pieces since 2003
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      Good question. The

      &sortby=`RAND()`

      or
      &sortby=`FIELD(modResource.id, 4,7,2,5,1 )`


      gets you started... but it doesn't handle the daily refresh.

      Ideally, there'd be an "&cache" parameter that let you set a number of seconds that the thing would be cached, so it could refresh every day.

      The only work-around I can think of would either be to cron something in the command line that cleared the cache programmatically on a daily basis, or write a snippet that relied on modular division ...

      If you're just grabbing one post, you probably don't even need getResources... [ed. note: Everettg_99 last edited this post 14 years, 9 months ago.]
        • 4172
        • 5,888 Posts
        have a snippet for evo, which can be adapted to revo:

        <?php
        //[[daylidoc? &parent=`13`&chunkname=`daylidoc`&excludedocs=`18`]]
        //[[daylidoc? &parent=`13`&chunkname=`daylidoc`&mode=`week`&dayoffset=`5`]]
        
        $chunkname = isset ($chunkname)?$chunkname:'daylidoc';
        $mode = isset ($mode)?$mode:'day';//day,week,month
        $dayoffset = isset ($dayoffset)?$dayoffset:1;
        
        if ( isset ($parent))
        {
            $table = $modx->getFullTablename('site_htmlsnippets');
            $rs = $modx->db->select('*', $table, 'name="'.$chunkname.'"');
            $chunk = $modx->db->getRow($rs);
        
            date_default_timezone_set('Europe/Berlin');
            switch($mode)
            {
                case 'month':
                    $dateformat = '%m.%Y';
        			$date = @strftime($dateformat);
                    break;
                case 'week':
                    $timestamp=time();
        			$ts_dow = ($w = date("w", $timestamp))?$w:7;
                    $ts_day = strftime("%d", $timestamp);
                    $ts_month = strftime("%m", $timestamp);
                    $ts_year = strftime("%Y", $timestamp);
                    $timestampweekstart = mktime(0, 0, 0, $ts_month, $ts_day-$ts_dow+$dayoffset, $ts_year);
        			$dateformat = '%d.%m.%Y';
        			$date = 'week starts at '.@strftime($dateformat,$timestampweekstart);
                    break;
                case 'day':
                default:
                    $dateformat = '%d.%m.%Y';
        		    $date = @strftime($dateformat);
            }
        	
            $fields['description'] = 'randomID for '.$date;
            $randomDocID = $chunk['snippet'];
        
            if (is_array($chunk)){
            	$excludedocs=isset($excludedocs)?explode(',',$excludedocs):array();
        		$excludedocs[]=$randomDocID;
        		$excludedocs=implode(',',$excludedocs);
            }
           $excludedocs=isset($excludedocs)?' AND id not IN ('.$excludedocs.')':'';
        	
            if (is_array($chunk))
            {
                if ($fields['description'] !== $chunk['description'])
                {
                    $table2 = $modx->getFullTablename('site_content');
                    $rs = $modx->db->select('id,rand() as random', $table2, 'parent='.$parent.$excludedocs, 'random', '1');
                    $randomdoc = $modx->db->getRow($rs);
                    if (is_array($randomdoc))
                    {
                        $fields['snippet'] = $randomDocID = $randomdoc['id'];
                        $modx->db->update($fields, $table, 'name="'.$chunkname.'"');
                    }
                  
                }
        
            }
            else
            {
                $table2 = $modx->getFullTablename('site_content');
                $rs = $modx->db->select('id,rand() as random', $table2, 'parent='.$parent.$excludedocs, 'random', '1');
                $randomdoc = $modx->db->getRow($rs);
                if (is_array($randomdoc))
                {
                    $fields['snippet'] = $randomDocID = $randomdoc['id'];
                    $fields['name'] = $chunkname;
                    $modx->db->insert($fields, $table);
                }
        
            }
        }
        
        return $randomDocID;
        ?>
        
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 36786 ☆ A M B ☆
          • 209 Posts
          THANKS!
            Ben Morrison
            Hacking templates to pieces since 2003
          • discuss.answer
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: Everettg_99 at Dec 28, 2011, 02:50 PM
            Ideally, there'd be an "&cache" parameter that let you set a number of seconds that the thing would be cached, so it could refresh every day.

            The only work-around I can think of would either be to cron something in the command line that cleared the cache programmatically on a daily basis, or write a snippet that relied on modular division ...

            If you're just grabbing on post, you probably don't even need getResources...
            Just wrap getResources with the getCache Snippet. This should support everything you need to set cache items which expire at specific times or intervals from any Snippet that returns it's output.
              • 36786 ☆ A M B ☆
              • 209 Posts
              Ok so thats even easier, thanks guys! I didn't even know about the getCache snippet... now I have a few other ideas to try smiley
                Ben Morrison
                Hacking templates to pieces since 2003