Stand With Ukraine. Stop Putin. Stop War.

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.

Andrew Smith

This is a great article Mark, thanks for the insight as to excluding Articles from the getResources.

messyp

I spent so long trying to work out why my getresources call was not showing any articles on my homepage, thanks for the tip thought it was a bug

??????? ?????? ?????????????? ?? ?????????

Thank you Mark, for this article, but this doesn't work for me.
How can i limit the number of items - articles shown in Wayfinder submenu? I have menu Smth -s1,s2,s3 Articles-a1,a2,a3, if &limit=`3`, Wayfinder displays only Smth -s1,s2. With no limits articles will overload menu someday.
Another problem, ok hidden articles, Wf shows 1 level menu, but in this level dependent articles it shows menu using activeParentRowTpl, so have problems with some css. Need advise, thanks!

Amal

Ok - a few questions, and the answers will help others.

I have a NEWS front page that I actually want to use to grab a glob of news from an article and then a link to the article.

For example:

------
Lorem Vel Metus Vitala (

Comments are closed :(

While I would prefer to keep comments open indefinitely, the amount of spam that old articles attract is becoming a strain to keep up with and I can't always answer questions about ancient blog postings. If you have valuable feedback or important questions, please feel free to get in touch.