Early in my life clouds began to catch my eyes. During school, I couldn’t sit by windows in class without being helplessly distracted. Later in life, if I needed to clear my mind, I’d just step outside...
Soon I began expressing this fascination artistically. In fact, this attraction has been one of the major muses for my photography and, as my domain suggests, this web site. And so it is also the purpose of the web site - to distract you for a few moments by sharing some of the scenes which have taken my attention in the past few years.
RSS/XML: Photos & Articles | Photos | Links
Have you ever longed for the ability to display a bit of information stored in Textpattern, but you couldn’t find a way to access it? zem has greatly helped this issue, by sharing a very useful bit of code in the Textpattern Forums about accessing the url_title variable. In fact, this code helped solve a usability issue in my Photo Gallery that I couldn’t address otherwise (I’ll give you more details in a future post).
If you are running a recent build of RC3 (somewhere around of March 13, 2005) you should be able to use the Textpattern php tags to access this information (Note: Per zem, these tags may or may not make it into 1.0). For instance, the following code will display the url title for the current article:
<txp:php>echo $GLOBALS['thisarticle']['url_title'];</txp:php>
So, for this article the above code will display:
url_title: accessing-global-variables-in-textpatternThis becomes incredibly useful, because we can use this code to access any global variable by simply switching out the variables in the statement of code. I.E. if you wanted to display the last time your website was modified, you could enter:
<txp:php>echo $GLOBALS['prefs']['lastmod'];</txp:php>
And thanks to research shared by Henrik Jönsson in Global Variables in Textpattern. We now have a list of the variables which allow us to directly access this information through Textpattern pages, articles and forms!
Below I have listed a brief description, most known global variables and their corresponding Textpattern tags. Please help me flesh out any additional details or point out any inaccuracies in the comments.
| Textpattern Global Variables | ||
| Description | Global Variable | Textpattern Tag |
|---|---|---|
| $prefs | Site Preferences | |
| Unknown | ['prefs']['prefs_id'] | |
| Site Name | ['prefs']['sitename'] | <txp:sitename /> |
| Path from Root | ['prefs']['path_from_root'] | |
| Web Domain | ['prefs']['siteurl'] | |
| Site Tagline | ['prefs']['site_slogan'] | |
| Language | ['prefs']['language'] | |
| Timeoffset | ['prefs']['timeoffset'] | |
| Date Format | ['prefs']['dateformat'] | |
| Achive Dateformat | ['prefs']['achive_dateformat'] | |
| URL Mode | ['prefs']['url_mode'] | |
| Send Lastmodified Header | ['prefs']['send_lastmod'] | |
| Ping Weblogs.com | ['prefs']['ping_weblogsdotcom'] | |
| Logging | ['prefs']['logging'] | |
| Records Mentions | ['prefs']['records_mentions'] | |
| Use Textile | ['prefs']['use_textile'] | |
| Use Categories | ['prefs']['use_categories'] | |
| Use Sections | ['prefs']['use_sections'] | |
| Use Comments | ['prefs']['use_comments'] | |
| Comments Moderate | ['prefs']['comments_moderate'] | |
| Comments on Default | ['prefs']['comments_on_default'] | |
| Comments Default Invite | ['prefs']['comments_default_invite'] | |
| Comments Dateformat | ['prefs']['comments_dateformat'] | |
| Comments Mode | ['prefs']['comments_mode'] | |
| Comments Sendmail | ['prefs']['comments_sendmail'] | |
| Comments Disallow Images | ['prefs']['comments_disallow_images'] | |
| Comments Disabled After | ['prefs']['comments_disabled_after'] | |
| RSS How Many | ['prefs']['rss_how_many'] | |
| Date Site Last Modified | ['prefs']['lastmod'] | |
| Days Log Entries Exist | ['prefs']['logs_expire'] | |
| Directory to Images | ['prefs']['img_dir'] | |
| Textpattern Version | ['prefs']['version'] | |
| $pretext | A Mix of Site & Article Data | |
| Current Article ID | ['pretext']['id'] | <txp:id /> |
| Current Section | ['pretext']['s'] | <txp:s /> |
| Current Page | ['pretext']['page'] | <txp:page /> |
| CSS | ['pretext']['css'] | <txp:css /> |
| Current Category | ['pretext']['c'] | <txp:c /> |
| Search Results | ['pretext']['q'] | <txp:q /> |
| Unknown | ['pretext']['count'] | <txp:count /> |
| Current Page | ['pretext']['pg'] | <txp:pg /> |
| Unknown | ['pretext']['p'] | <txp:p /> |
| Next ID | ['pretext']['next_id'] | <txp:next_id /> |
| Next Title | ['pretext']['next_title'] | <txp:next_title /> |
| Next URL Title | ['pretext']['next_utitle'] | <txp:next_utitle /> |
| Previous Article ID | ['pretext']['prev_id'] | <txp:prev_id /> |
| Previous Title | ['pretext']['prev_title'] | <txp:prev_title /> |
| Previous URL Title | ['pretext']['prev_utitle'] | <txp:prev_utitle /> |
| Path from Root | ['pretext']['path_from_root'] | <txp:path_from_root /> |
| Subdirectory | ['pretext']['pfr'] | <txp:pfr /> |
| URL mode | ['pretext']['url_mode'] | <txp:url_mode /> |
| Site Name | ['pretext']['sitename'] | <txp:sitename /> |
| $thisarticle | Article Data | |
| Current Article ID | ['thisarticle']['thisid'] | <txp:article_id /> |
| Author | ['thisarticle']['author'] | <txp:author /> |
| Posted Date | ['thisarticle']['posted'] | <txp:posted /> |
| If comments? | ['thisarticle']['if_comments'] | |
| Comments Invite | ['thisarticle']['comments-invite'] | <txp:comments_invite /> |
| Comments Count | ['thisarticle']['comments_count'] | <txp:comments_count /> |
| Permanent Link | ['thisarticle']['permlink'] | <txp:permlink></txp:permlink> |
| Title | ['thisarticle']['title'] | <txp:title /> |
| Article Excerpt | ['thisarticle']['excerpt'] | <txp:excerpt /> |
| Body | ['thisarticle']['body'] | <txp:body /> |
| Article URL Title | ['thisarticle']['url_title'] | |
| Category 1 | ['thisarticle']['category1'] | <txp:category1 /> |
| Category 2 | ['thisarticle']['category2'] | <txp:category2 /> |
| Article Section | ['thisarticle']['section'] | <txp:section /> |
| Keywords | ['thisarticle']['keywords'] | <txp:meta_keywords /> |
| Article Image | ['thisarticle']['article_image'] | <txp:article_image /> |
| $thispage | More Article Data | |
| Current Pagenumber | ['thispage']['pg'] | |
| Total Pages of Articles | ['thispage']['numPages'] | |
| Current Section | ['thispage']['s'] | <txp:s /> |
| Current Category | ['thispage']['c'] | <txp:c /> |
You can find zem’s Textpattern Forum post here.
You can find a more detailed list of global variables here.
Unfortunately, I’ve had to the close comments due to the number of spam items I’ve recieved. Please e-mail me at focusontheclouds@gmail.com if you have a question or would like to add a comment.
Home | Archive | Photography | My Diversions | About
© 2006 Matt Harris. All Rights Reserved.
# On Jul 25, 11:12 AM, Henrik said:
I know it was some time ago you wrote this but great job. You’ve created a great chart for easy overview! I do know that there have been addons to the variables and I plan to do a print_r dump when I get home and install the new RC4 and see what new interesting things are available and maybe do a writeup on my article :)
# On Jul 25, 12:17 PM, Matt Harris said:
Thanks Henrik! I’ll be looking forward to any new functionality which we can add to this list…
# On Jan 30, 02:40 PM, Ashur said:
One item that I could not find without jumping into the source was the correct reference for custom fields.
$GLOBALS[‘thisarticle’][‘Name of Custom Field’]
Obvious when you find it, frustrating until then.
# On Jul 19, 12:15 PM, Jonathan Clarke said:
['pretext']['author'] doesn't seem to work, shouldn't it be ['thisarticle']['author']# On Jul 19, 01:57 PM, Matt Harris said:
You are correct. Evidently, I used cut & paste a little carelessly. Thanks for pointing it out.
On a side note, unless you are using it for some on-page php you shouldn’t need to use [‘pretext’][‘author’] – the author tag should work fine.
# On Jul 20, 09:22 AM, Jonathan Clarke said:
Yes, Sencer confirms it here also: http://forum.textpattern.com/viewtopic.php?id=17515
Trouble is, I really need to use some on-page PHP.
# On Jul 20, 09:23 AM, Jonathan Clarke said:
Sorry, to be absolutely clear, Sencer is saying tha t author isn’t available via the GLOBALS variables. You should update your list.
# On Oct 23, 11:10 PM, Nathan Smith said:
I am a little late to the party, having just found this article. I just wanted to say thanks – this is just what I was looking for!