Skip to content

Instantly share code, notes, and snippets.

@bajanReece
Created March 19, 2013 11:37

Revisions

  1. bajanReece created this gist Mar 19, 2013.
    38 changes: 38 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    <?php

    function get_taxonomy_content($tid, $limit = 10) {
    /**
    A note on variables:
    field_data_field_article_rating --- this is the name of taxonomy table you're referring to
    field_article_rating_tid --- this is the name of the term ID column in the table above
    **/

    $out = array();


    $query = db_select('node', 'n');
    $query->join('field_data_field_article_rating', 'c', 'n.nid = c.entity_id');
    $query->condition('n.status', 1, '=')
    ->condition('c.field_article_rating_tid', $tid)
    ->fields('n', array('nid', 'title'))
    ->orderBy('n.type', 'ASC');

    $query = $query->extend('PagerDefault')->limit($limit);


    $result = $query->execute();

    foreach($result as $row){
    // first we get the node content
    $nodeObj = node_view(node_load($row->nid),'teaser');
    // then we get the node URL
    $options = array('absolute' => TRUE);
    $url = url('node/' . $row->nid, $options);
    // then we output an array
    $out[$row->nid] = array('nid'=>$row->nid, 'title'=>$row->title, 'obj'=>$nodeObj, 'url'=>$url);
    } // end foreach

    return $out;

    }
    ?>