Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-10-19 21:20:31

wchung
Member
Registered: 2009-04-23
Posts: 29

Displaying Other Articles by the Same Author within an Article

Hello:

We have several columnists on our site.

For each article by a columnist, I would like to display a list of the 10 most recent articles by the same author.

I can’t define the list using section or category as that would list articles by all our other columnists.

I would like to avoid having to create a separate page template and section for every one of our columnists.

Is there a tag that would do this?

Thanks!

Offline

#2 2009-10-19 21:51:09

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Displaying Other Articles by the Same Author within an Article

<txp:article_custom limit="10" author="author name" />

Offline

#3 2009-10-19 21:58:47

wchung
Member
Registered: 2009-04-23
Posts: 29

Re: Displaying Other Articles by the Same Author within an Article

Els,

Thanks for responding, but wouldn’t that tag require a separate page template for each author?

I am trying to avoid having a separate template/section for each of several authors.

Offline

#4 2009-10-19 22:08:29

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Displaying Other Articles by the Same Author within an Article

No, just use one tag for each author where you want to display the articles. Something like this:

<h3>Articles by John Smith</h3>
<txp:article_custom form="yourform" limit="10" author="John Smith" />

<h3>Articles by Bill Clinton</h3>
<txp:article_custom form="yourform" limit="10" author="Bill Clinton" />

...etcetera

Offline

#5 2009-10-19 22:15:17

wchung
Member
Registered: 2009-04-23
Posts: 29

Re: Displaying Other Articles by the Same Author within an Article

Maybe I wasn’t clear in my question…

We have a number of authors whose articles are all published in the “perspectives” section of the site, under the “Editorial” category.

For each article by any author, I would like to provide on the left column a list of other articles by that same author (and if possible, omitting the article that is currently being presented on the page).

Offline

#6 2009-10-19 22:46:02

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Displaying Other Articles by the Same Author within an Article

Ah, sorry I misunderstood. You mean on an individual article page? Maybe this would work (not tested):

<txp:if_individual_article>
	<h3>Recent articles by this author</h3>
	<txp:article_custom author='<txp:author />' limit="10" wraptag="ul">
		<txp:if_article_id>
		<txp:else />
			<li><txp:permlink><txp:title /></txp:permlink></li>
		</txp:if_article_id>
	</txp:article_custom>
</txp:if_individual_article>

Offline

#7 2009-10-19 22:52:50

wchung
Member
Registered: 2009-04-23
Posts: 29

Re: Displaying Other Articles by the Same Author within an Article

Els,

That was it! This will save me having to create a whole bunch of pages/sections!

Thanks!

Offline

#8 2009-10-19 23:53:30

wchung
Member
Registered: 2009-04-23
Posts: 29

Re: Displaying Other Articles by the Same Author within an Article

Els,

Hate to bother you again, but it seems the tags only work with one author.

It’s either because that’s the first author or it’s the only author in which the login and the real name are identical.

For the other authors the tags just show a blank space.

Any thoughts? Could it be a bug in textpattern?

Offline

#9 2009-10-20 00:56:09

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Displaying Other Articles by the Same Author within an Article

author attribute for article_custom needs to be the login name. The only way I know to get that is with raw PHP, like so:

<txp:article_custom wraptag="ul" author='<txp:php>global $thisarticle; echo $thisarticle["authorid"];</txp:php>'>
	<txp:if_article_id>
	<txp:else />
		<li><txp:permlink><txp:title /></txp:permlink></li>
	</txp:if_article_id>
</txp:article_custom>

Code is topiary

Offline

#10 2009-10-20 02:08:09

wchung
Member
Registered: 2009-04-23
Posts: 29

Re: Displaying Other Articles by the Same Author within an Article

Jeff,

It worked like a charm! I will have to save it in my collection of useful codebits.

Thanks to both of you!

Offline

#11 2009-10-20 08:27:54

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Displaying Other Articles by the Same Author within an Article

jsoo wrote:

author attribute for article_custom needs to be the login name.

Ah, thanks Jeff! I never use <txp:author /> myself, so I didn’t think about that. So if I understand this correctly, the author tag could do with a name and title attribute like the section and category tags?

Offline

#12 2009-10-20 11:46:03

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Displaying Other Articles by the Same Author within an Article

Yes, that’s a good idea, given that we’re talking about accessing core functionality. author has its link attribute but that wouldn’t have worked for the OP’s very reasonable request. Given how the tag currently works you’d need to make title true by default (unlike with section) for compatibility. I guess you’d also want to remind designers not to display login names publicly.


Code is topiary

Offline

Board footer

Powered by FluxBB