1. 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

Discussion in 'XenForo Development Discussions' started by LPH, Mar 30, 2013.

  1. LPH

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

    xf_phantom Well-Known Member

    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);
     
     
    Bob and LPH like this.
  3. LPH

    LPH Well-Known Member

    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?
     
  4. xf_phantom

    xf_phantom Well-Known Member

    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
     
  5. LPH

    LPH Well-Known Member

    Again - thank you for the help.


    I think this was found and corrected.



    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 ;)
     
  6. LPH

    LPH Well-Known Member

    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:
     
  7. LPH

    LPH Well-Known Member

    Screen Shot 2013-03-30 at 8.20.32 AM.png


    Once again xf_phantom .... thank you for the help. This works like a charm.
     
    Reeve of Shinra likes this.
  8. xenTheory

    xenTheory Active Member

    Great work!
     

Share This Page