<?php $template = (isset($template)) ? $template : '1'; $c = $modx->newQuery('modResource'); $c->leftJoin('modTemplate','Template'); $c->where(array( 'published' => true, )); if (is_numeric($template)) { $c->where(array('template' => $template));} else { $c->where(array('Template.templatename' => $template)); mail('[email protected]', 'non-numeric'); } $resources = $modx->getCollection('modResource',$c); foreach($resources as $res) { $id = $res->get('id'); if ($modx->resource->get('id') != $id) { $opts[] = $res->get('pagetitle') . '==' . $res->get('id'); } } return implode('||', $opts); ?>
I’m trying to use this snippet as output to a TV, to list all the resources that use a given template - *except* for the ID of the current resource.
Everything is working except for the "is this the current resource" part. I’m getting the error
"PHP Fatal error: Call to a member function get() on a non-object"
Is $modx->resource not available from within a TV? If not, how do I get the ID of the current resource?
$modx->log(modX::LOG_LEVEL_ERROR,'My message here.');
$modx->setLogTarget('ECHO'); $modx->log(modX::LOG_LEVEL_ERROR,'Output me to the screen.');
@EVAL return 'inherit||none' . $modx->runSnippet('getResourcesByTemplate', array('template'=>'21'));
Ah, @EVAL. *shudder*. Yes, Custom TVs were meant to kill off @EVAL. But if that works - that should be fine.
This isn’t for a custom TV - I haven’t ventured in to those waters yet. It is a snippet for populating a regular TV. Basically, I am populating a dropdown list box (the TV input) with the IDs and pagetitles of all the other resources that use this same template.
Oh, maybe.
Is this what you meant when you said you would be mocking me?
Try $resourceId, and see if that works.
@EVAL return 'inherit||none' . $modx->runSnippet('getResourcesByTemplate', array('template'=>'21', 'pid'=>$resourceId));
@EVAL return $modx->runSnippet('get_like_count');
<?php $source_url = $modx->makeUrl($modx->documentIdentifier, '', '', 'full'); $url = "http://api.facebook.com/restserver.php?method=links.getStats&urls=".urlencode($source_url); $xml = file_get_contents($url); $xml = simplexml_load_string($xml); $shares = $xml->link_stat->share_count; $likes = $xml->link_stat->like_count; $comments = $xml->link_stat->comment_count; $total = $xml->link_stat->total_count; $max = max($shares,$likes,$comments); return strip_tags($likes); ?>