Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2013-01-12 19:28:44
- rcpinheiro
- Member
- Registered: 2013-01-12
- Posts: 11
Numeric author ID in posts
Hi!
Unfortunately, since TXP doesn’t have a way to include an avatar for a post author, I’ve decided to create to a quick solution. So I created a “avatar” folder to put all the admin avatars and then included this in form default:
<txp:php>
global $thisarticle;
echo ‘<img src=“avatar/”.$thisarticle[‘authorid’].’.jpg” />”;
</txp:php>
The problem is that some authorid are complex, include accented characters and non-latin characters. It would be a mess to name the avatar file name the same as the author name. So, instead I’m looking for a way to include the numeric author ID but didn’t found it.
Does anyone know how to do this? Or fiddling with SQL is the only way to get this information?
Thanks in advance!
PS: Sorry if this is a newbie question ;)
Offline
Re: Numeric author ID in posts
<txp:author title="0" />
will output author’s login, which (normally) does not contain non-latin characters. If you need it inside a php block, call author(array('title'=>0))
.
Edit: sorry, I was too self-confident, it’s the same as thisarticle['authorid']
.
Last edited by etc (2013-01-12 20:02:49)
Offline
Offline
#4 2013-01-13 11:37:48
- rcpinheiro
- Member
- Registered: 2013-01-12
- Posts: 11
Re: Numeric author ID in posts
Many thanks for the answers.
etc, smd_bio does what I needed but I’m trying anyway to try to get the ID in the form. This doesn’t work (fetch is empty), any idea why?
<txp:php>
global $thisarticle;
echo "The ID is ".fetch('user_id', 'txp_users', 'name', doSlash($thisarticle['authorid']))."<br>";
</txp:php>
PS: Using version 4.5.4
{Edited to add Textile’s bc..
for correctly displaying straight/curly apostrophes. – Uli}
Last edited by uli (2013-01-13 13:44:37)
Offline
Re: Numeric author ID in posts
It works for me, both in article body and in article form. Actually, doSlash
is not needed (and may cause problems), it’s done internally by fetch
anyway. Try to call it in debug mode:
<txp:php>
global $thisarticle;
echo "The ID is ".fetch('user_id', 'txp_users', 'name', $thisarticle['authorid'], true)."<br>";
</txp:php>
Offline
#6 2013-01-13 15:10:46
- rcpinheiro
- Member
- Registered: 2013-01-12
- Posts: 11
Re: Numeric author ID in posts
Thanks, etc.
Debug mode showed me the problem: it seems TXP has problems with accented characters!
This works (shown using debug mode):
select user_id from txt_txp_users where `name` = 'jose' limit 1
This doesn’t:
select user_id from txt_txp_users where `name` = 'josé' limit 1
The problem is worse than this because the link to the author posts also doesn’t work:
http://domain.com/author/jos%C3%A9
It seems TXP doesn’t support AuthorIDs with non-ASCII characters or it has a serious bug.
Offline
Re: Numeric author ID in posts
I was able to retrieve a non-ascii author’s user_id
, and the corresponding link works ok, so the problem must be somewhere else. Make sure josé
has some live articles in searchable (?) front-page sections. If you use the code above in article body, make sure that josé
has sufficient privileges to run <txp:php>
. Also check (with phpmyadmin?) what is in txp_users
table.
Last edited by etc (2013-01-13 18:14:16)
Offline
#8 2013-01-13 18:05:06
- rcpinheiro
- Member
- Registered: 2013-01-12
- Posts: 11
Re: Numeric author ID in posts
Ops, found the bug. It was a silly typo from me, sorry about that :(
For the record: this works for all type of characters (I tested with chinese and other weird stuff)
fetch('user_id', 'txp_users', 'name', $thisarticle['authorid']).
Offline
#9 2013-01-14 12:32:51
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,306
Re: Numeric author ID in posts
rcpinheiro wrote:
It seems TXP doesn’t support AuthorIDs with non-ASCII characters or it has a serious bug.
Robert/wet himself opened an issue on January 6, that could have to do with what you’ve experienced. I’d like to ask you to read that short page and – if you think your problem might be related – add information to it. Thanks.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: Numeric author ID in posts
This issue might be related to double doSlash
(once in get_author_name/email
, and once more in fetch
functions; that’s what I meant above).
Offline
#11 2013-01-14 20:08:31
- rcpinheiro
- Member
- Registered: 2013-01-12
- Posts: 11
Re: Numeric author ID in posts
Hi, uli!
No relation, afaik. I haven’t tested with ‘ or “ characters, only with accented and non-latin characters used in oriental and latin person names.
Offline
Pages: 1