Hi,
My client wants a link to the latest blogpost. I'm using Articles for the blog.
Now how can i get that link? something like [[~[[latestArticleId]]]]
thanks
RDG
There's probably a built-in way to do it, but this should also work, and will be very fast:
[[!LatestArticleUrl]]
/* LatestArticleUrl Snippet */
$query = $modx->newQuery('modResource');
$query->where(
array(
'class_key' => 'Article',
'published' => 1,
'deleted' => 0,
),
);
$query->sortby('publishedon', 'DESC');
$query->limit(1);
$query->select('id');
$docId = $modx->getValue($query->prepare());
return $modx->makeUrl($docId, "", "", "full");
Hi BobRay,
Thanks for the answer. How can i tell the snippet which instance of articles it is supposed to look in?
I have 3 different Articles in my site
Thanks
RDG
If they are direct children of different resources, this should do it:
$query->where(
array(
'class_key' => 'Article',
'published' => 1,
'deleted' => 0,
'parent' => $idOfParentContainer,
),
);