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
Re: another txp tag nesting php query
When I put it into test-mode the only difference was a pair of empty <code>pre</code> tags above the list. Is this just a side-effect of the <code><txp:php></code> code, or sign of something more significant?
The results of the diagnostic <code>dmp()</code> call were that the list still showed all authors… should there be anything extra hidden in the source from using that approach? I couldn’t see anything unusual.
I’ve never really use ‘Debug’ mode so I’m not sure what’s happening there (& there doesn’t seem to be a FAQ for debugging)… theres a lot of stuff at the bottom of the source but the page renders the same and the list still shows all authors. Would it be useful to see the debuggin source output? – theres a lot of it!
Hard-coding does work as expected… might have to resort to hard-coding all the usernames within <code>if_author</code> conditionals. Ouch!
But if it definately works on your install I might build a clean install somewhere and try it again… could it be a clash with a plugin or something?
Last edited by pieman (2006-05-17 07:36:30)
Offline
Re: another txp tag nesting php query
pieman wrote:
When I put it into test-mode the only difference was a pair of empty <code>pre</code> tags above the list. Is this just a side-effect of the <code><txp:php></code> code, or sign of something more significant?
This is the output of the dmp function which should embrace the value of “title” the subsequent php snippet relies on, and that is the reason why this whole mess exists. Obviously, $thisarticle['title'] does not containg a value. This is contradictory to the fact that there is a call to txp:article preceeding the php snippet as you said. Please double check.
theres a lot of stuff at the bottom of the source but the page renders the same and the list still shows all authors. Would it be useful to see the debuggin source output? – theres a lot of it!
In debugging mode, Textpattern appends a “tag trace” as a HTML comment at the end of the page listing every tag Textpattern encounters in the sequence in which they occur. It not very simple to dig through but it might give you another clue of whether there is really a call for txp:article…
Would you mind sharing this tag trace (everything from the HTML comments at the page’s end)? Post here to avoid Textiling the whole mess… You made me curious, as this works as expected on my dev site ;-)
Offline
Re: another txp tag nesting php query
glad I made you so curious ;)
I posted my full page template so you can see the other <code>txp:article</code> calls above.
And my tag trace
Offline