Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
another txp tag nesting php query
Hello
I’m working on a multi-user site. To create an ‘about’ page for each admin user, I’m writing each person a single article using their login name as the article title. Then I can generate a link to this page from any article I write, using the using the bos_author plugin in my article form.
eg. with clean URLs my ‘about’ page is at www.site.com/about/pieman
Then in that page I’d like to generate a list of links to all the articles that I’ve authored.
So I’d like to write the current article’s title as a attribute of an article_custom tag.
<code><txp:article_custom author=”<txp:title />” form=“nav” /></code>
It’s not gonna work because I’ve nested two Txp tags…
Could anyone suggest another approach, or even tell me how I could write that code in php?
many thanks
Stu
Offline
Re: another txp tag nesting php query
<txp:php>
echo article_custom( array ( "author" => title( array() ), "form" => "nav" ));
</txp:php>
…or something very similar.
Last edited by wet (2006-05-15 20:46:15)
Offline
Re: another txp tag nesting php query
cheers wet
it doesn’t quite work as planned – it lists articles by all authors instead.
(but any excuse to check out your rock ‘tache is appreciated…)
Offline
Re: another txp tag nesting php query
pieman wrote:
‘tache
Whazz that? Got it. Facial hair, he said…
Back on topic: Do use use said php
snippet in an article list, page template, an article or a form? Would mind sharing what’s above and below and ‘round this line?
Last edited by wet (2006-05-16 11:54:24)
Offline
Re: another txp tag nesting php query
this is what I’ve got so far:
- in the page template:<code>
<txp:if_individual_article>
<h3>by this person</h3>
<txp:article_custom form=“articles_byAuthor” />
</txp:if_individual_article>
</code>
- in the “articles_byAuthor” form:<code> <txp:php> echo article_custom( array ( “author” => title( array() ), “form” => “list_articlesByAuthor” )); </txp:php></code>
- and in the “list_articlesByAuthor” form:<code><li><txp:permlink><txp:title /></txp:permlink> <txp:section /><txp:posted /> by <txp:author /></li></code>
Using this configuration it seems to be aware that we’ve specified an author value, because in each about/username page it’s limiting the output to one author – just not the right one! I can’t see any obvious reason for it always being this particular author… but it’s always the same one, regardless of the current article title.
thanks again
Stu
Offline
Re: another txp tag nesting php query
I was able to reproduce the effects you are experiencing.
You are nesting article_custom
invocations which is not supported and will fail in subtle ways. So, if that effect is not “subtle” ;-) (NB: A recent changeset works on lifting that restriction).
Plus, there’s no need for the second form.
I was successful with the following solution:
Include all of “articles_byAuthor” into the page template itself replacing your previous call to <txp:article_custom form="articles_byAuthor" />
(either directly or by utilising txp:output_form
):
[...]
<txp:if_individual_article>
<h3>by this person</h3>
<ul>
<txp:php>
echo article_custom( array ( "author" => title( array() ), "form" => "list_articlesByAuthor" ));
</txp:php>
</ul>
</txp:if_individual_article>
[...]
Drop “articles_byAuthor”. It is obsoleted.
Leave “list_articlesByAuthor” as-is.
Works for me & hth.
Robert
Offline
Re: another txp tag nesting php query
thanks Robert
with that appoach, the list generates articles by ALL authors….
hmmm
who is ‘hth’ by the way?
Offline
Re: another txp tag nesting php query
Does your template contain a call to txp:article
prior to the snippet posted above?
Otherwise, title()
is empty and will not filter byany author. See the manual for txp:article, attribute pageonly
.
HTH,
Robert
Offline
Re: another txp tag nesting php query
Dump the contents of title
to see if it is set:
<txp:php>
// diagnostic code
global $thisarticle;
dmp ( $thisarticle['title'] );
// end of diagnostic code
echo article_custom( array ( "author" => title( array() ), "form" => "list_articlesByAuthor" ));
</txp:php>
Does this render any result?
Last edited by wet (2006-05-16 18:54:43)
Offline
Re: another txp tag nesting php query
Yes, there is another txp:article above in the page template…. I think that without quite grasping why, my reason for nesting an extra form was to make sure the title value was set. And it did set something with that nested approach – cos the list was reduced to a single (wrong) author.
I tried the new code and get the same result as last time… a list by all authors, which suggests the title wasn’t set before doesn’t it?
Could we try hard-coding an author’s name into the title value to see if that works?
thanks very much Robert – tis much appreciated
Last edited by pieman (2006-05-16 20:47:56)
Offline
Re: another txp tag nesting php query
I am stumped as it works as intended on my development site with a default page template. What are the results of the diagnostic dmp()
call? Are there any messages when you put your site in “Testing” or “Debug” mode?
pieman wrote:
Could we try hard-coding an author’s name into the title value to see if that works?
Certainly. Use this:
echo article_custom( array ( "author" => "pieman", "form" => "list_articlesByAuthor" ) );
This has to render the expected output…
Last edited by wet (2006-05-17 04:16:55)
Offline