Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-09-30 14:50:49

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

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

#2 2020-09-30 15:27:25

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,595
GitHub Twitter

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

#3 2020-09-30 15:41:33

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

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

#4 2020-09-30 16:17:47

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

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 evaluated.


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,303

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

#6 2020-09-30 16:44:20

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

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

#7 2020-09-30 18:57:38

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

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

#8 2020-09-30 19:14:28

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

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

#9 2020-10-01 08:16:50

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

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

#10 2020-10-01 08:24:44

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

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

#11 2020-10-01 08:57:20

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

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

#12 2020-10-01 09:07:29

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Authors listings only if more than 1 author exists

Bloke wrote #326182:

Also, what would the result be without pgonly?

Non-numeric pageby and pgonly are not used atm, suggestions welcome. That could be as well

<txp:article_custom pgonly="AuthorID" />

Offline

Board footer

Powered by FluxBB