Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Not This Section

// description of your code here

<txp:if_section name="notthissection">
<!-- do nothing -->
<txp:else />
blah blah
</txp:if_section>

Serving links to multilingual pages

http://forum.textpattern.com/viewtopic.php?id=12371

Let’s assume you want to have two sets of pages which would be crosslinked with links like “see this page in [another language]”. Set custom fields for the languages you want to support, name them, for example eng and ukr (for English and Ukrainian).

Write articles for those languages and assign them links of their sibling articles on the other language, say, you have an article in English with permanent link “/about/my-dog” and you have the same article in Ukrainian with permanent link “/about/my-dog-ukr”, then set “/about/my-dog” to the custom field “eng” in the article on Ukrainian and “/about/my-dog-ukr” to the custom field “ukr” in the article on English.

Then in the article form you use write a code similar to the following:

<txp:if_custom_field name=“eng”>
<a href=”<txp:custom_field name=“eng” />”>this page in english</a>
</txp:if_custom_field>

<txp:if_custom_field name=“ukr”>
<a href=”<txp:custom_field name=“ukr” />”>this page in ukrainian</a>
</txp:if_custom_field>


That’s it! When it’s English link to Ukrainian article will be shown up and vice versa.
It’s just a basic example to give you an idea, hope it helps.

Article list from same category / section as current article

From a post on the Textpattern support forums.

<ul><txp:asy_wondertag><txp:article_custom limit="9999" form="listarticles" section="<txp:section />" category="<txp:category1 />" /></txp:asy_wondertag></ul>

Return a message on blank search form submit

From a post on the Textpattern support forums.

<txp:php> if(gps('q') == '') echo 'Hey, remember to search something!'; </txp:php>

Post link to POOKMARK with Textpattern

Simple link to post each individual article to Japanese social bookmark "POOKMARK".

POOKMARK Airlines
http://pookmark.jp/

<a href="http://pookmark.jp/post?url=<txp:permlink />&title=<txp:title />" title="">POOKMARK THIS</a>

Technorati Link Count Widget for Textpattern

Technorati tracks when other bloggers link to your blog and this widget makes it possible for you to display the number of links on every blog post. We call them "reactions" to encourage readers to follow the conversation. To add the widget, copy and paste the code below into your blog's template.

<script src="http://embed.technorati.com/linkcount" type="text/javascript"></script>
<a href="http://technorati.com/search/<txp:permlink />" rel="linkcount">View blog reactions</a>

Adding "post to" links for del.icio.us, digg, and ma.gnolia in Textpattern

Here's how to add "post to" links for del.icio.us, digg, and ma.gnolia to individual articles in Textpattern

del.icio.us

post to <a href="http://del.icio.us/post?url=<txp:permlink />&amp;title=<txp:title />">del.icio.us</a> 


digg

post to <a href="http://www.digg.com/submit?phase=2&amp;url=<txp:permlink />">digg</a>


ma.gnolia

post to <a href="http://ma.gnolia.com/bookmarklet/add?url=<txp:permlink />&amp;title=<txp:title />">ma.gnolia</a>


Clicking one of the those links will automatically post a permanent link for an article and, in the case of del.icio.us and ma.gnolia, the title to one of the above services.

Photoblogging with Textpattern: atom feeds

To textpattern/publish/atom.php somewhere around line 131 (in 4.0.2), or after
else {
$Body = '';
// If there's no excerpt, use body as content instead of body as summary
if (!trim($Excerpt))
$Body = fixup_for_feed($thisarticle['body'], permlinkurl($a));
}

add this:
// hack to get pictures to syndicate
if ($a['Section'] == "photo")
{
$img_url = hu."images/".$a['Image'].'.jpg';
$Body = doSpecial('<a href="'.permlinkurl($a).'"><img src="'.$img_url.'" alt="the latest and greatest" /></a>');
}
// /hack

Photoblogging with Textpattern: rss feeds

Add this to textpattern/publish/rss.php somewhere around line 62 (in 4.0.2), or after "$Body = (!trim($Body)) ? $thisarticle['body'] : $Body;":
// hack to get pictures to syndicate
if ($a['Section'] == "photo")
{
$img_url = hu."images/".$a['Image'].'.jpg';
$Body = doSpecial('<a href="'.permlinkurl($a).'"><img src="'.$img_url.'" alt="the latest and greatest" /></a>');
}
// /hack

Testing if this is NOT a category listing

The new releases of textpattern tend to use the new "yoursite.com/category/ZZZ" url format for category listing links. Which means that those category-filtered archives use the "default" template for formatting & so forth.

To handle this on the front page, you need to be able to test if the current view IS a category search, and you also need to test if this ISN't a category search (to display normal front-page content). To do this I had to modify the glx_if plugin - very easy really.

In Textpattern, go to admin > plugins, and click the "edit" link for glx_if. Add the following function anywhere it would seem to fit:

function glx_if_not_category_list($atts, $thing)
{
	global $pretext, $is_article_list;
	return (empty($pretext["c"]) && $is_article_list == true) ? parse($thing) : "";
}


A use for this is shown in this snippet.