pdoPage: Published and Unpublished Count

Revo 2.7.1
pdoTools 2.12.3

I’m using pdoPage to list all the resources by page title (published and unpublished, a.k.a. drafts) created by each user. So far so good.

I’m also showing a numerical breakdown of the above listing. While it works the “count” part needs some fine-tuning.

For example, if the user has 5 (published) and 2 (unpublished) articles the count currently looks like this:

Articles: 7
Drafts: 2

The problem is that the drafts are being counted as part of the (published) total which I don’t want.

What I want is this:

Articles: 5
Drafts: 2

I’m aware this is happening because I have showUnpublished=1 enabled but I need it this way in order to also show the unpublished resources by pagetitle. So what I’m looking for is a way to further filter the “count” to get it to display as:

Articles: 5
Drafts: 2

[[!pdoPage?
&elementClass=`modSnippet`
&element=`pdoResources`
&parents=`2`
&resources=`-1`
&includeTVs=`1`
&where=`{"createdby:=":[[!+modx.user.id]]}`
&showHidden=`1`
&sortby=`publishedon`
&sortdir=`DESC`
&tpl=`ArticleResult`
&hideContainers=`1`
&limit=`3`
&pageLimit=`5`
&toPlaceholder=`articleResult`
&totalVar=`articleTotal`
&setTotal=`1`
&pageNavVar=`page.nav.article`
&showUnpublished=`1`
&pageVarKey=`articles`
&tplPageActive=`@INLINE <li class="active">[[+pageNo]]</li>`]]

[[!pdoPage?
&elementClass=`modSnippet`
&element=`pdoResources`
&parents=`2`
&resources=`-1`
&where=`{"createdby:=":[[!+modx.user.id]], "AND:published:=":0}`
&showHidden=`1`
&showUnpublished=`1`
&hideContainers=`1`
&toPlaceholder=`articleDraftResult`
&totalVar=`articleDraftTotal`
&setTotal=`1`
&tpl=`@INLINE <span class="highlight">[[+articleDraftTotal]]</span>`]]

<h1>[[!+articleResult:gt=`0`:then=`<span class="highlight">[[+articleTotal]]</span> Article[[!pluralFilter? &count=`[[+articleTotal]]`]]`:else=`<span class="highlight">0</span> Articles`]] | [[!+articleDraftResult:gt=`0`:then=`Draft[[!pluralFilter? &count=`[[+articleDraftTotal]]`]] <span class="highlight">[[+articleDraftTotal]]</span>`:else=`Drafts <span class="highlight">0</span>`]]</h1>

If you need to display all the page titles yet have a different count to the resources specified, you may need to write a custom snippet for it.
There could of course be some pdoTools wizardry I’m unaware of though!

Is it not possible to display the 5 page titles from the first call and the other 2 from the second call?

I think as suggested you’ll need a small custom snippet that you could input the two counts and then find the difference
[[!Calc? &pubCount=[[+pubCount]] &unpubCount=[[+unpubCount]]]]`

Then in the snippet just take the two values and find the difference (7 - 2) and return the result for the article count.

@muzzstick I haven’t tried that yet but I will. It might be the path of least resistance. Thanks.

@lkfranklin I have almost no experience writing PHP but your suggestion is very interesting. I will have to investigate further. Thank you.

1 Like

Would go with @lkfranklin 's solution.

(untested)
Calc.snippet

<?php 

$total = $pubCount;
$minus = $unpubCount;

$new = $total - $minus;

return $new;