We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27023
    • 36 Posts
    Using Modx Revolution and getResources. I have built a blog as per the tutorial that splittingred posted.

    Everything is working perfectly and i am displaying all the category/sections (containers) in the sidebar. However i’m wanting to also display on each blog post what category/section it is in. I’ve tried using getResources within the chunk called by the initial getResources call that displays the blog posts, however this is not working at all...?

    Can someone possibly help? This is what i have in the chunk called by getResources

    <!--BEGIN .post-->
    <div class="post clearfix">
       <div class="post-image">
          <a href="[[~[[+id]]]]" title="[[+pagetitle]]"><img src="[[+tv.blogImage]]" alt="[[+pagetitle]]" height="230" width="280" class="rounded-all" /></a>
          <a href="[[~[[+id]]]]#comments" class="comment-count button-unselected rounded-all">([[!QuipCount? &thread=`blog-post-[[+id]]`]]) Comments</a>
          <a href="[[~[[+id]]]]" class="more-link button rounded-all">Read more »</a>
       </div>
    
    <div class="post-content-wrapper">
        <h2 class="post-title"><a href="[[~[[+id]]]]" title="[[+pagetitle]]">[[+pagetitle]]</a></h2>
    
    <div class="post-meta rounded-all">
         <span class="author">by [[+createdby:userinfo=`fullname`]]</span>
         <span class="published"> on <abbr class="published-time">[[+publishedon:strtotime:date=`%b %d, %Y`]]</abbr></span>
         <span class="post-categories"> in [[!getResources? &parents=`[[+id]]` &showHidden=`1` &includeContent=`1`]]
    </span>
         [[+tv.tags:notempty=`<span class="post-tags">Tags: [[!tolinks? &items=`[[+tv.tags]]` &key=`tag` &target=`24`]]
    </span>`]]</p>
    </div>
    
    <div class="post-text">
    <p>[[+introtext]]</p>
    </div>
     
    </div>
    <!--END .post-->
    </div>
    <div class="hr"><hr /></div>
    
    


    This is the line in question:

         <span class="post-categories"> in [[!getResources? &parents=`[[+id]]` &showHidden=`1` &includeContent=`1`]]
    </span>
      • 11927
      • 105 Posts
      I would be interested in something like this too. So far for evo I was using the snippet tagLinks. (Not sure where I got it, but also not sure if it is supported by Revo.)

      Is there a parameter that can be used or tv that needs to be created to make getResources or getPage show a list of the categories or tags for each blog post?




      But if anyone is interested here is the snippet.

      <?php
      /**
      * Gets the tags for the current page (if any are set),
      * from a specified tv and creates links to category pages
      * with an alias that is the same as the tag (only lower case
      * and without spaces).
      *
      * PHP versions 4 and 5
      *
      * @name       tagLinks
      * @category   Tagging/Blogging with Ditto for MODx
      * @author     Scotty Delicious <[email protected]>
      *             http://scottydelicious.com | http://piratemachine.org
      * @copyright  2007 Scotty Delicious
      * @license    http://www.gnu.org/copyleft/gpl.html GPL License 2.0
      * @version    1.0.5
      * @link       http://modxcms.com/
      * @see        http://scottydelicious.com/index.html
      * @since      File available since Release 1.0
      * @example    on a page: [[tagLinks? &tv=`tags` &separator=`, `]]
      * @example    ditto 2.0 tpl: [[tagLinks? &id=`[+id+]` &value=`[+tags+]` &separator=`, `]] with &hiddenFields=`tags` added to the Ditto call
      * @changes	  23-April-07: Trim all tags and url values to ensure page validitiy and compatibility with Ditto
      * 			  9-May-07: Allow for tv value to be passed to the snippet for performance when used within a looping snippet (e.g. Ditto)
      * 			  1.0.4: Allow a ModX Doc ID to be supplied as a path, instead of hard coding. Fixed error pointed out by Astronut on the forum regarding getTemplateVarOutput returning an array rather than a string 
      *			  1.0.5: Remove FAP parameter - using ModX API to generate the link takes care of this automatically. Respect Modx config value for XHTML URLs. Generate URLs better (use appropriate ? or &) - ncrossland
      * 
      * Parameters:
      * &id = document id to get tags for. default is
      *       current document.  When using this in a
      *       ditto tpl, use &id=`[+id+] to get the tags
      *       for the document being summarized.
      *
      * &tv = name of the template variable used for
      *       setting categories.
      *
      * &value = value of the tv if it has already
      *		been retrieved
      *
      * &delimiter = delimiter used in the tv.
      *       defaults to a comma ","
      *
      * &caseSensitive = remove tags that are the
      * 		same word but were written using different
      * 		cases. defaults to false.
      *
      * &label = Label listed before the list of links.
      *       defaults to "Categories: ".
      *
      * &separator = character to separate tag links.
      *       comma (,) or pipe (|) for example.
      *       defaults to '' (blank).
      *
      * &element = Element to wrap this in [div/span/p].
      *       defaults to "div".
      *
      * &style = CSS tag to apply to the &element.
      *       defualts to "taglinks".
      *
      * &format = format of the output for links. can be an
      *       anchor `a`, unordered list `ul`, or an ordered
      *       list `ol`
      *
      * &newline = add new line after each element.
      *       defaults to '1' (yes, add new lines).
      *       set to `0` and new lines will not be added.
      *
      * &path = path to your categories page. if your
      *       category pages are under "yoursite.url/blog/categories/",
      *       you would set &path=`blog/categories`. 
      *		Alternatively, supply a doc ID number, and it will
      * 		be converted to a path automagically.
      *
      ***************************************/
      
      /**
      * Set values for items that were not set in the
      * snippet call.
      */
      $page_id = isset($id) ? $id : $modx->documentObject['id'];
      $tv = isset($tv) ? $tv : '';
      $delimiter = isset($delimiter) ? $delimiter : ',';
      $label = isset($label) ? $label : 'Categories: ';
      $separator = isset($separator) ? $separator : '';
      $element = isset($element) ? $element : 'div';
      $style = isset($style) ? $style : 'taglinks';
      $format = isset($format) ? $format : 'a';
      $newline = isset($newline) ? $newline : '1';
      $path = isset($path) ? $path : '';
      $caseSensitive = isset($caseSensitive) ? $caseSensitive : 0;
      
      // If a numeric path is supplied, assume it is a modx page ID, so create a URL from it
      if (!empty($path) && is_numeric($path)) {
      	$path = $modx->makeUrl($path);	
      }
      
      // Do we need to make the URL ampersands XHTML compatible?
      $amp = $modx->config['xhtml_urls'] == '1'?'&':'&';
      
      /**
      * Get the tags from the TV the user supplied
      */
      if ($tv == '' && !isset($value)){return "No template variable for tags was declared.";}
      $get_tags = isset($value) ? $value : implode($delimiter,$modx->getTemplateVarOutput($idname=array($tv), $page_id, $published="1"));
      
      /**
      * Make an array of all the tags associated with the specified document.
      */
      $tags = array();
      $tvarray = explode($delimiter, $get_tags);
      foreach ($tvarray as $tag) {
      	if (!empty($tag)) {
      		if ($caseSensitive) {
      			$tags[trim($tag)] = trim($tag);
      		} else {
      			$tags[strtolower(trim($tag))] = trim($tag);
      		}
      	}
      }
      $tvarray = array_values($tags);
      $cnt = count($tvarray);
      
      /**
      * Build the URL
      */
      $url_seperator = (strpos($path, '?') === false)?'?':$amp;
      $doc_path = $path.$url_seperator.'tags=';
      
      
      /**
      * Remove new lines if &newline is set to `0`.
      */
      if ($newline == '1'){
      	$nl = "\n";
      } else {
      	$nl = '';
      }
      
      /**
      * Create the containing element (<div>, <span>, or <p>)
      * and give it the style declared in &style.
      */
      $link .= '<'.$element.' class="'.$style.'">'.$nl;
      
      /**
      * Create a series of HTML anchors with hrefs if &format
      * is set to `a`.
      */
      if ($format == 'a'){
      $link .= "$label";
      	for ($x=0;$x<$cnt;$x++) {
      		$url = urlencode(trim($tvarray[$x]));
      		$cnd_separator = ($x!=($cnt-1)) ? $separator : '';
      	   $link .= '<a href="'.$doc_path.strtolower($url).'">'.trim($tvarray[$x]).'</a>'.$cnd_separator.$nl;	
      	}
      } else {
      
      /**
      * Otherwise genereate a series of list items with a hrefs if &format
      * is set to ordered or unordered list.
      */
      	$link .= '<'.$format.'>'.$nl;
      	$link .= '<li class="'.$style.'_label">'.$label.'</li>'.$nl;
      	for ($x=0;$x<$cnt;$x++) {
      		$url = urlencode(trim($tvarray[$x]));
      		$cnd_separator = ($x!=($cnt-1)) ? $separator : '';
      	   $link .= '<li><a href="'.$doc_path.strtolower($url).'">'.trim($tvarray[$x]).'</a>'.$cnd_separator.'</li>'.$nl;
      	}
      	$link .= '</'.$format.'>'.$nl;
      }
      
      /**
      * Close the containing element.
      */
      $link .= '</'.$element.'>'.$nl;
      
      /**
      * If the array is empty (because no tags were attached to the document)
      * return nothing as to not disturb the page layout.
      */
      if ($tvarray['0'] == ''){
      	return;
      }else{
      
      /**
      * Otherwise return the links to the page!
      */
      return $link;
      }


      keywords: category
        You may or may not want to use the code I write. It&#39;s probably all against the syntax rules of php and MODx. smiley

        Carpet Cleaning
        • 11927
        • 105 Posts
        I took some time and I think I made it Revo compatible. The second example is a little modification I made to have it go to the specific topic page, instead of just a generic page for all topics. ie. instead of the link being this /topics.html?tags=specific-topic it would be this /topics/specific-topic.html (I did this more for SEO purposes.)



        (I’m not sure if the [[+tags]] works. I never tested it.)
        #1
        <?php
        /**
        * Gets the tags for the current page (if any are set),
        * from a specified tv and creates links to category pages
        * with an alias that is the same as the tag (only lower case
        * and without spaces).
        *
        * PHP versions 4 and 5
        *
        * @name       tagLinks
        * @category   Tagging/Blogging with Ditto for MODx
        * @author     Scotty Delicious <[email protected]>
        *             http://scottydelicious.com | http://piratemachine.org
        * @copyright  2007 Scotty Delicious
        * @license    http://www.gnu.org/copyleft/gpl.html GPL License 2.0
        * @version    1.0.5
        * @link       http://modxcms.com/
        * @see        http://scottydelicious.com/index.html
        * @since      File available since Release 1.0
        * @example    on a page: [[tagLinks? &tv=`tags` &separator=`, `]]
        * @example    ditto 2.0 tpl: [[tagLinks? &id=`[[+id]]` &value=`[[+tags]]` &separator=`, `]] with &hiddenFields=`tags` added to the Ditto call
        * @changes	  23-April-07: Trim all tags and url values to ensure page validitiy and compatibility with Ditto
        * 			  9-May-07: Allow for tv value to be passed to the snippet for performance when used within a looping snippet (e.g. Ditto)
        * 			  1.0.4: Allow a ModX Doc ID to be supplied as a path, instead of hard coding. Fixed error pointed out by Astronut on the forum regarding getTVValue returning an array rather than a string 
        *			  1.0.5: Remove FAP parameter - using ModX API to generate the link takes care of this automatically. Respect Modx config value for XHTML URLs. Generate URLs better (use appropriate ? or &) - ncrossland
        * 
        * Parameters:
        * &id = document id to get tags for. default is
        *       current document.  When using this in a
        *       ditto tpl, use &id=`[[+id]]` to get the tags
        *       for the document being summarized.
        *
        * &tv = name of the template variable used for
        *       setting categories.
        *
        * &value = value of the tv if it has already
        *		been retrieved
        *
        * &delimiter = delimiter used in the tv.
        *       defaults to a comma ","
        *
        * &caseSensitive = remove tags that are the
        * 		same word but were written using different
        * 		cases. defaults to false.
        *
        * &label = Label listed before the list of links.
        *       defaults to "Categories: ".
        *
        * &separator = character to separate tag links.
        *       comma (,) or pipe (|) for example.
        *       defaults to '' (blank).
        *
        * &element = Element to wrap this in [div/span/p].
        *       defaults to "div".
        *
        * &style = CSS tag to apply to the &element.
        *       defualts to "taglinks".
        *
        * &format = format of the output for links. can be an
        *       anchor `a`, unordered list `ul`, or an ordered
        *       list `ol`
        *
        * &newline = add new line after each element.
        *       defaults to '1' (yes, add new lines).
        *       set to `0` and new lines will not be added.
        *
        * &path = path to your categories page. if your
        *       category pages are under "yoursite.url/blog/categories/",
        *       you would set &path=`blog/categories`. 
        *		Alternatively, supply a doc ID number, and it will
        * 		be converted to a path automagically.
        *
        ***************************************/
        
        /**
        * Set values for items that were not set in the
        * snippet call.
        */
        $page_id = isset($id) ? $id : $modx->resource->get('id');
        $tv = isset($tv) ? $tv : '';
        $delimiter = isset($delimiter) ? $delimiter : ',';
        $label = isset($label) ? $label : 'Categories: ';
        $separator = isset($separator) ? $separator : '';
        $element = isset($element) ? $element : 'div';
        $style = isset($style) ? $style : 'taglinks';
        $format = isset($format) ? $format : 'a';
        $newline = isset($newline) ? $newline : '1';
        $path = isset($path) ? $path : '';
        $caseSensitive = isset($caseSensitive) ? $caseSensitive : 0;
        
        // If a numeric path is supplied, assume it is a modx page ID, so create a URL from it
        if (!empty($path) && is_numeric($path)) {
        	$path = $modx->makeUrl($path);	
        }
        
        // Do we need to make the URL ampersands XHTML compatible?
        $amp = $modx->config['xhtml_urls'] == '1'?'&':'&';
        
        /**
        * Get the tags from the TV the user supplied
        */
        if ($tv == '' && !isset($value)){return "No template variable for tags was declared.";}
        $page = $modx->getObject('modResource', $page_id);
        $get_tags = isset($value) ? $value : $page->getTVValue( $tv );
        
        /**
        * Make an array of all the tags associated with the specified document.
        */
        $tags = array();
        $tvarray = explode($delimiter, $get_tags);
        foreach ($tvarray as $tag) {
        	if (!empty($tag)) {
        		if ($caseSensitive) {
        			$tags[trim($tag)] = trim($tag);
        		} else {
        			$tags[strtolower(trim($tag))] = trim($tag);
        		}
        	}
        }
        $tvarray = array_values($tags);
        $cnt = count($tvarray);
        
        /**
        * Build the URL
        */
        $url_seperator = (strpos($path, '?') === false)?'?':$amp;
        $doc_path = $path.$url_seperator.'tags=';
        
        
        /**
        * Remove new lines if &newline is set to `0`.
        */
        if ($newline == '1'){
        	$nl = "\n";
        } else {
        	$nl = '';
        }
        
        /**
        * Create the containing element (<div>, <span>, or <p>)
        * and give it the style declared in &style.
        */
        $link .= '<'.$element.' class="'.$style.'">'.$nl;
        
        /**
        * Create a series of HTML anchors with hrefs if &format
        * is set to `a`.
        */
        if ($format == 'a'){
        $link .= "$label";
        	for ($x=0;$x<$cnt;$x++) {
        		$url = urlencode(trim($tvarray[$x]));
        		$cnd_separator = ($x!=($cnt-1)) ? $separator : '';
        	   $link .= '<a href="'.$doc_path.strtolower($url).'">'.trim($tvarray[$x]).'</a>'.$cnd_separator.$nl;	
        	}
        } else {
        
        /**
        * Otherwise genereate a series of list items with a hrefs if &format
        * is set to ordered or unordered list.
        */
        	$link .= '<'.$format.'>'.$nl;
        	$link .= '<li class="'.$style.'_label">'.$label.'</li>'.$nl;
        	for ($x=0;$x<$cnt;$x++) {
        		$url = urlencode(trim($tvarray[$x]));
        		$cnd_separator = ($x!=($cnt-1)) ? $separator : '';
        	   $link .= '<li><a href="'.$doc_path.strtolower($url).'">'.trim($tvarray[$x]).'</a>'.$cnd_separator.'</li>'.$nl;
        	}
        	$link .= '</'.$format.'>'.$nl;
        }
        
        /**
        * Close the containing element.
        */
        $link .= '</'.$element.'>'.$nl;
        
        /**
        * If the array is empty (because no tags were attached to the document)
        * return nothing as to not disturb the page layout.
        */
        if ($tvarray['0'] == ''){
        	return;
        }else{
        
        /**
        * Otherwise return the links to the page!
        */
        return $link;
        }





        #2
        <?php
        /**
        * Gets the tags for the current page (if any are set),
        * from a specified tv and creates links to category pages
        * with an alias that is the same as the tag (only lower case
        * and without spaces).
        *
        * PHP versions 4 and 5
        *
        * @name       tagLinks
        * @category   Tagging/Blogging with Ditto for MODx
        * @author     Scotty Delicious <[email protected]>
        *             http://scottydelicious.com | http://piratemachine.org
        * @copyright  2007 Scotty Delicious
        * @license    http://www.gnu.org/copyleft/gpl.html GPL License 2.0
        * @version    1.0.5
        * @link       http://modxcms.com/
        * @see        http://scottydelicious.com/index.html
        * @since      File available since Release 1.0
        * @example    on a page: [[tagLinks? &tv=`tags` &separator=`, `]]
        * @example    ditto 2.0 tpl: [[tagLinks? &id=`[[+id]]` &value=`[[+tags]]` &separator=`, `]] with &hiddenFields=`tags` added to the Ditto call
        * @changes	  23-April-07: Trim all tags and url values to ensure page validitiy and compatibility with Ditto
        * 			  9-May-07: Allow for tv value to be passed to the snippet for performance when used within a looping snippet (e.g. Ditto)
        * 			  1.0.4: Allow a ModX Doc ID to be supplied as a path, instead of hard coding. Fixed error pointed out by Astronut on the forum regarding getTVValue returning an array rather than a string 
        *			  1.0.5: Remove FAP parameter - using ModX API to generate the link takes care of this automatically. Respect Modx config value for XHTML URLs. Generate URLs better (use appropriate ? or &) - ncrossland
        * 
        * Parameters:
        * &id = document id to get tags for. default is
        *       current document.  When using this in a
        *       ditto tpl, use &id=`[[+id]]` to get the tags
        *       for the document being summarized.
        *
        * &tv = name of the template variable used for
        *       setting categories.
        *
        * &value = value of the tv if it has already
        *		been retrieved
        *
        * &delimiter = delimiter used in the tv.
        *       defaults to a comma ","
        *
        * &caseSensitive = remove tags that are the
        * 		same word but were written using different
        * 		cases. defaults to false.
        *
        * &label = Label listed before the list of links.
        *       defaults to "Categories: ".
        *
        * &separator = character to separate tag links.
        *       comma (,) or pipe (|) for example.
        *       defaults to '' (blank).
        *
        * &element = Element to wrap this in [div/span/p].
        *       defaults to "div".
        *
        * &style = CSS tag to apply to the &element.
        *       defualts to "taglinks".
        *
        * &format = format of the output for links. can be an
        *       anchor `a`, unordered list `ul`, or an ordered
        *       list `ol`
        *
        * &newline = add new line after each element.
        *       defaults to '1' (yes, add new lines).
        *       set to `0` and new lines will not be added.
        *
        * &path = path to your categories page. if your
        *       category pages are under "yoursite.url/blog/categories/",
        *       you would set &path=`blog/categories`. 
        *		Alternatively, supply a doc ID number, and it will
        * 		be converted to a path automagically.
        *
        ***************************************/
        
        /**
        * Set values for items that were not set in the
        * snippet call.
        */
        $page_id = isset($id) ? $id : $modx->resource->get('id');
        $tv = isset($tv) ? $tv : '';
        $delimiter = isset($delimiter) ? $delimiter : ',';
        $label = isset($label) ? $label : 'Categories: ';
        $separator = isset($separator) ? $separator : '';
        $element = isset($element) ? $element : 'div';
        $style = isset($style) ? $style : 'taglinks';
        $format = isset($format) ? $format : 'a';
        $newline = isset($newline) ? $newline : '1';
        $path = isset($path) ? $path : '';
        $caseSensitive = isset($caseSensitive) ? $caseSensitive : 0;
        
        // If a numeric path is supplied, assume it is a modx page ID, so create a URL from it
        if (!empty($path) && is_numeric($path)) {
        	$path = $modx->makeUrl($path);	
        }
        
        // Do we need to make the URL ampersands XHTML compatible?
        $amp = $modx->config['xhtml_urls'] == '1'?'&':'&';
        
        /**
        * Get the tags from the TV the user supplied
        */
        if ($tv == '' && !isset($value)){return "No template variable for tags was declared.";}
        $page = $modx->getObject('modResource', $page_id);
        $get_tags = isset($value) ? $value : $page->getTVValue( $tv );
        
        /**
        * Make an array of all the tags associated with the specified document.
        */
        $tags = array();
        $tvarray = explode($delimiter, $get_tags);
        foreach ($tvarray as $tag) {
        	if (!empty($tag)) {
        		if ($caseSensitive) {
        			$tags[trim($tag)] = trim($tag);
        		} else {
        			$tags[strtolower(trim($tag))] = trim($tag);
        		}
        	}
        }
        $tvarray = array_values($tags);
        $cnt = count($tvarray);
        
        /**
        * Build the URL
        */
        $url_seperator = (strpos($path, '?') === false)?'?':$amp;
        /* custom edit previous code:
        	$doc_path = $path.$url_seperator.'tags=';
        */
        $doc_path = str_replace('.html', '', $path ) .'/';
        
        
        
        
        /**
        * Remove new lines if &newline is set to `0`.
        */
        if ($newline == '1'){
        	$nl = "\n";
        } else {
        	$nl = '';
        }
        
        /**
        * Create the containing element (<div>, <span>, or <p>)
        * and give it the style declared in &style.
        */
        $link .= '<'.$element.' class="'.$style.'">'.$nl;
        
        /**
        * Create a series of HTML anchors with hrefs if &format
        * is set to `a`.
        */
        if ($format == 'a'){
        $link .= "$label";
        	for ($x=0;$x<$cnt;$x++) {
        		/* custom edit previous code:
        			$url = urlencode(trim($tvarray[$x]));
        		*/
        		$url = str_replace('+', '-', urlencode(trim($tvarray[$x])) ) .'.html';
        		
        		
        		$cnd_separator = ($x!=($cnt-1)) ? $separator : '';
        	   $link .= '<a href="'.$doc_path.strtolower($url).'">'.trim($tvarray[$x]).'</a>'.$cnd_separator.$nl;	
        	}
        } else {
        
        /**
        * Otherwise genereate a series of list items with a hrefs if &format
        * is set to ordered or unordered list.
        */
        	$link .= '<'.$format.'>'.$nl;
        	$link .= '<li class="'.$style.'_label">'.$label.'</li>'.$nl;
        	for ($x=0;$x<$cnt;$x++) {
        		$url = urlencode(trim($tvarray[$x]));
        		$cnd_separator = ($x!=($cnt-1)) ? $separator : '';
        	   $link .= '<li><a href="'.$doc_path.strtolower($url).'">'.trim($tvarray[$x]).'</a>'.$cnd_separator.'</li>'.$nl;
        	}
        	$link .= '</'.$format.'>'.$nl;
        }
        
        /**
        * Close the containing element.
        */
        $link .= '</'.$element.'>'.$nl;
        
        /**
        * If the array is empty (because no tags were attached to the document)
        * return nothing as to not disturb the page layout.
        */
        if ($tvarray['0'] == ''){
        	return;
        }else{
        
        /**
        * Otherwise return the links to the page!
        */
        return $link;
        }
          You may or may not want to use the code I write. It&#39;s probably all against the syntax rules of php and MODx. smiley

          Carpet Cleaning