Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Authors listings only if more than 1 author exists
Good afternoon,
I’m currently, in spare moments, building a theme for Textpattern – which I’ll share more details on soon.
However, in the theme I only want to expose author listings if there is actually more than 1 author that has written articles in the CMS. i.e. only hyperlink the <txp:author />
tag and have author listing pages if articles by multiple authors exist (otherwise it doesn’t make sense to have article listings by author if the site only has 1 author).
Is this doable? Can you share some code that detects this?
Cheers!
Offline
Re: Authors listings only if more than 1 author exists
Tested with only one author and multiples ones:
<txp:evaluate query='<txp:authors /> > 1'>Multiple authors<txp:else />1 author</txp:evaluate>
So you may use a <txp:variable />
into this line for more flexibility.
Last edited by Pat64 (2020-09-30 15:27:48)
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
Re: Authors listings only if more than 1 author exists
Thanks Patrick – but doesn’t that just check how many authors are registered in the CMS, not if articles have actually been written by them.
I’m guessing that’ll be an article_custom tag query, somehow?
Offline
Re: Authors listings only if more than 1 author exists
It may work with a variable
containing the if_different
tag the result of which can then be evaluate
d.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#5 2020-09-30 16:37:08
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,304
Re: Authors listings only if more than 1 author exists
Ah, thanks, Yiannis, your if_different
made me aware: We’ve had a very similar request not long ago.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: Authors listings only if more than 1 author exists
Ah, OK, thanks all. So the way Oleg demonstrated is not very performant, it seems?
I could probably go with Patrick’s suggestion – it’s better than not having anything at all. Shame there is no tag that covers the situation properly though.
Offline
Re: Authors listings only if more than 1 author exists
You can
<txp:php>
echo getThing('SELECT COUNT(DISTINCT AuthorID) FROM textpattern WHERE Status > 3');
</txp:php>
Or register getThing
for use in <txp:evaluate />
and
<txp:evaluate query="getThing('SELECT COUNT(DISTINCT AuthorID) FROM textpattern WHERE Status > 3')" />
But yes, a tag or attribute would be handy.
Offline
Re: Authors listings only if more than 1 author exists
<txp:variable name="multipleauthors" value="0" />
<txp:article limit="9999">
<txp:if_different>
<txp:variable name="meaninglessvalue" value='<txp:author />' />
<txp:variable name="multipleauthors" add="1" />
</txp:if_different>
</txp:article>
<txp:if_variable name="multipleauthors" value="1" >
There is only one author.
<txp:else />
There are multiple authors.
</txp:if_variable>
Offline
Re: Authors listings only if more than 1 author exists
etc wrote #326178:
Or register
getThing
for use in<txp:evaluate />
and
<txp:evaluate query="getThing('SELECT COUNT(DISTINCT AuthorID) FROM textpattern WHERE Status > 3')" />...
I have tried to use this code but I get a tag error (the PHP example works though) – do I need any other code to make this version work? I’m concious that if I use the PHP version then users with ‘Use PHP in pages’ pref turned off will get errors.
Offline
Re: Authors listings only if more than 1 author exists
philwareham wrote #326180:
I have tried to use this code but I get a tag error (the PHP example works though) – do I need any other code to make this version work?
Works for me. Have you added getThing
to Advanced options > PHP functions enabled in txp:evaluate
?
Anyway, it’s easy to add this functionality to <txp:article_custom />
, we just have to choose an attribute. Would this do
<txp:article_custom pgonly pageby="AuthorID" />
or we need a new attribute?
Edit registering getThing
is risky, since you users will be able to run db queries.
Offline
Re: Authors listings only if more than 1 author exists
etc wrote #326181:
<txp:article_custom pgonly pageby="AuthorID" />...
Fine by me if it’s not too confusing. Anything else makes sense here in pageby
while we’re at it? Our current definition is:
pageby=“integer” The number of articles to output per page.
So we’d need to figure out how to reword that accordingly.
Also, what would the result be without pgonly
?
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Offline