XF 1.5 Resources sidebar on forum list

Sunka

Well-known member
What to change to not show default X newest resources in sidebar (This controls the maximum number of new resources to display on the forum list page...), but X random resources.

Thank you
 
It will be an easy change. To show resources in random order instead of newest, go to the XenResource_Listener_Template file and find this part of code:

PHP:
$resources = $resourceModel->getResources(
            array(
                'moderated' => false,
                'deleted' => false
            ),
            array(
                'join' => XenResource_Model_Resource::FETCH_VERSION
                    | XenResource_Model_Resource::FETCH_USER
                    | XenResource_Model_Resource::FETCH_CATEGORY,
                'permissionCombinationId' => XenForo_Visitor::getInstance()->permission_combination_id,
                'limit' => $latestResources * 2
            )
        );

Then change it to this:

PHP:
$resources = $resourceModel->getResources(
            array(
                'moderated' => false,
                'deleted' => false
            ),
            array(
                'join' => XenResource_Model_Resource::FETCH_VERSION
                    | XenResource_Model_Resource::FETCH_USER
                    | XenResource_Model_Resource::FETCH_CATEGORY,
                'permissionCombinationId' => XenForo_Visitor::getInstance()->permission_combination_id,
                'order' => 'rand()',
                'limit' => $latestResources * 2
            )
        );

It is untested, but it should work.
 
That wouldn't actually work.

We only support a small number of order clauses, see XenResource_Model_Resource::prepareResourceOrderOptions.

Besides which, using MySQL's RAND() function is awful in terms of performance so what you're looking to do would likely require custom development and likely more than a few lines of code to do it properly.
 
Last edited:
I fully agree about the performance affects of rand() function. I should have mentioned that in my previous post. Thank you for bringing it up sir.

I also agree that this will require an add on to do it properly and I would use array_rand() function instead to display the latest reources randomly. But what I posted above was a quick dirty way to achive what the OP wanted on the fly.

I am aware of Resource_Model_Resource::prepareResourceOrderOptions, but modifying that, would not it affect the display of resources everywhere btw?
 
Last edited:
So, nothing at all...

Newest resources is nice when you have everyday new resource on forum, but if you have just one or two resources per month, then random resources sidebar is much better solution.
 
But what I posted above was a quick dirty way to achive what the OP wanted on the fly.

I am aware of Resource_Model_Resource::prepareResourceOrderOptions, but modifying that, would not it affect the display of resources everywhere btw?
It wouldn't work like you think it does.

You can't pass 'rand()' in as an option as it isn't a valid option. I'm not proposing changing that function, that's just to demonstrate which order options are valid.
 
Top Bottom