Since the launch of MODX Revolution 2.2pl, the use of the Articles blogging tool has been growing exponentially as well. This post walks you through a question that is being asked several times per day: how do I show Articles on my homepage or in a sidebar?
Including Articles in Wayfinder or getResources
As individual articles are stored and used just like any other resource, you can use the same tools to display them such as getResources or Wayfinder. The trick there is that Articles are set as hidden from menus, which both of these snippets hide by default. Luckily both of the mentioned snippets support including those as well using a simple property, as shown below.
[[- Display a list of the last 3 Articles from the Articles resource #17, sorted on publishdate]] [[Wayfinder? &ignoreHidden=`1` &startId=`17` &level=`1` &limit=`3` &sortBy=`publishedon` &sortOrder=`asc`]] [[getResources? &showHidden=`1` &parents=`17` &depth=`1` &sortby=`{"publishedon":"DESC"}` &tpl=`myTpl`]]
Wayfinder uses the &ignoreHidden property. As it is primarily a menu building tool, if you want it to to show hidden resources you tell it to ignore the hidden state. getResources is not linked with menus directly, and uses the &showHidden property to indicate you also want hidden resources to show up. So they do the same, but the terminology used for it is slightly different and can seem counter intuitive at first.
But what if you don't want them included?
Excluding Articles in Wayfinder or getResources
If you don't want the articles posts to show up in a Wayfinder menu or getResources list, you can filter them out by checking against the "class_key" variable.
Normal resources have that set to modDocument (or modWebLink, modSymLink or modStaticResource), but as Articles installs a custom resource class the class_key is different as well. The blog container itself is an ArticlesContainer class, and the individual articles are of class Article. Knowing this, we can filter against this using the &where property. This &where property, commonly available in extras, accepts a json string representing an array (with xPDOQuery::where style comparisons). That may sound complicated, but here's an example for Wayfinder and getResources:
[[Wayfinder? &startId=`0` &level=2` &ignoreHidden=`1` &where=`{"class_key:!=": "Article"}`]] [[getResources? &parents=`0` &depth=`2` &tpl=`myTpl` &where=`{"class_key:!=": "Article"}`]]
And that's all! Happy blogging!
Update!
Mere houres after publishing this article the MODX RTFM was updated with some more information on accessing all of the placeholders used in the Articles templates, including the latest articles, tags and comments. Find it here.
This is a great article Mark, thanks for the insight as to excluding Articles from the getResources.