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

Script to pull latest resources added to RM

LPH

Well-known member
#1
I would like to add a php script to pull the latest resources added to the resource manager to the bottom of my WordPress side of the site.

Here is my work so far, untested. As you can quickly see, something is not making sense on the url portion. How do I link to the resource?

PHP:
<?php
/* Script to pull the latest updated resources from the XF Resource Manager*/
 
/** @var $resModel  XenResource_Model_Resource */
$resModel = XenForo_Model::create('XenResource_Model_Resource');
$fetchOptions = array(
'limit' => 5,
'order' => 'resource_date',
'direction' => 'desc'
);
 
$rmupdates = $resModel->getResources(array(), $fetchOptions);
 
 
foreach ($rmupdates AS $rmupdate)
{
 
 
        echo ("<div class='entry-meta'><a href='/community/" . XenForo_Link::buildPublicLink('resources', $rmupdate) .    "' >" . $rmupdate['title'] . "</a> Downloaded: "  .$rmupdate['download_count'] .      "<br /></div>"); // Echo the title with a link.
 
}
 
?>
Updated php code in this post for anyone interested in using it.
 

xf_phantom

Well-known member
#2
Typo!
$rmupdate != $rumupdate ;)

Code:
foreach ($resources AS $rmupdate)
{
$latestrmupdates[$rumupdate['resource_id']] = array(
2. I would use this code to fetch the data instead of using a own query
PHP:
/** @var $resModel  XenResource_Model_Resource */
$resModel = XenForo_Model::create('XenResource_Model_Resource');
$fetchOptions = array(
'limit' => 5,
'order' => 'resource_date',
'direction' => 'desc'
);
 
$resources = $resModel->getResources(array(), $fetchOptions);
 

LPH

Well-known member
#3
Thank you for catching the rum typo as well as the suggested fetch. (y)

Now, I'd still run into the same issue, how do I get the resource url?
 

xf_phantom

Well-known member
#4
second problem
last_date => should be last_update
and for the link:

PHP:
XenForo_Link::buildPublicLink('full:resources', $rmupdate)
don't know why you're doing this
PHP:
$latestrmupdates[$rmupdate['resource_id']] = array(
'id' => $rmupdate['resource_id'],
'title' => $rmupdate['title'],
'url' => XenForo_Link::buildPublicLink('canonical:rmupdates', $rmupdate),
'latestupdate' => $rmupdate['last_update'],
'downloadcount' => $rmupdate['download_count']
);
if you don't use it:D
 

LPH

Well-known member
#5
Again - thank you for the help.

second problem
last_date => should be last_update
and for the link:

I think this was found and corrected.


don't know why you're doing this (in reference to several lines of code)

Well - I wish there was an answer which made better sense but I was pulling from other work and trying to modify it. Guess it can be stripped out ;)
 

LPH

Well-known member
#6
It's working ! :D

Now I need to clean up the general layout for the footer and the WordPress side will have links to the latest resources.

Very cool. Thank you xf_phantom. :notworthy: