Script to pull latest resources added to RM

LPH

Well-known member
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.
 
Typo!
$rmupdate != $rumupdate ;)

Rich (BB 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);
 
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?
 
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
 
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 ;)
 
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:
 
Top Bottom