1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.5 Resources sidebar on forum list

Discussion in 'Styling and Customization Questions' started by Sunka, Jan 22, 2016.

  1. Sunka

    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
     
  2. wang

    wang Well-Known Member

    I think that this will require custom developement.
     
    Sunka likes this.
  3. Sunka

    Sunka Well-Known Member

    Is it just few lines of code to change?
     
  4. wang

    wang Well-Known Member

    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.
     
  5. Chris D

    Chris D XenForo Developer Staff Member

    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: Jan 22, 2016
    Sunka and wang like this.
  6. wang

    wang Well-Known Member

    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: Jan 22, 2016
  7. Sunka

    Sunka Well-Known Member

    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.
     
  8. Chris D

    Chris D XenForo Developer Staff Member

    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.
     
  9. Sunka

    Sunka Well-Known Member

    Because it is not just few lines as I think it will be, I created thread in suggestion subforum.
     

Share This Page