18/03/07

How to setup a Textpattern playlist

There was once a time when my most-asked-question was “can you send me the Firefox logo vector originals please”. Nowadays, it’s “How did you do the playlist bit – is it a plugin?”. So to save repeating myself, I’m writing this up as a blog post.

First of all, I’m afraid it isn’t a plugin. While there are ways of using the Amazon API to pull out album cover images automatically, I’ve had mixed results. Sometimes its wrong, and sometimes it doesn’t stock the album., which as an anal cover fetishist, just isn’t acceptable.

So, before I go further, bear in mind that with Textpattern, you can add anything, and send to anywhere, and display it how you like it. While not completely automated, my system does at least allow me to update the playlist fairly quickly.

Here are the steps if you want to try to setting one up yourself:

  1. Create a new custom field called “Amazon URL”. This is used to store the link (My own setup is slightly different as it uses the ASIN instead)
  2. Create a new section called ‘Playlist’. Turn all the radio button options to ‘no’. This will give us a specific section to post to.
  3. Create an ‘article’ form called ‘covers’, and add the following:
    <li><a href="<txp:custom_field name="Amazon URL" />" title="<txp:title />">
          <txp:article_image />
    </a></li>
  4. In your page template, where you want the playlist to appear, add the following:
    <ul>
    <txp:article_custom form="covers" limit="9" section="playlist" sortby="Posted" sortdir="desc" />
    </ul>
    The article_custom tag is the key here. It isn’t context-sensitive like <txp:article /> and allows you to output content from a different section anywhere you like.

    Then I add the content. So being the aforementioned anal cover fetishist, I upload these manually via Content > Images. I then take a mental note of the image ID, go to the write tab, and enter this number in the ‘article image’ field.

    Then all that needs to be done is add the Title, and choose the correct section. Done!

    Technorati TagsTags: ,

23/01/07

hReview in Textpattern

That last post was a little test in using the hReview Microformat in Textpattern. I think it worked!

One of Textpattern’s great features is the ability to use a different ‘form’ (the template that specifies how posts are marked up) that each post uses. With this in mind, all you need to do is create a different article form called ‘hReview’ and specify that any time you do a review on a Textpattern blog.

I’ll come to the actual markup of the form in a moment, but first I just want to show you how I’ve used the Content > Write tab to write the review.

In this example, all I added were 2 custom fields (via Admin > Preferences > Advanced), ‘URL’ and ‘Rating’, but you may want to add more for fields such ‘Item Type’.

Then I entered the review as follows:

TXP Field name Microformat Class TXP Tag
Title Item <txp:title />
Excerpt Summary <txp:excerpt />
Body Description <txp:body />
Article Image* Photo <txp:article image class="photo" />
Rating (custom field) ** Rating <txp:custom_field name="Rating" />
URL (custom field) URL <txp:custom_field name="URL" />

*The Textpattern ID of the image

**Entered as a number from 1-5

I then chose ‘hReview’ from the ‘Override form’ dropdown before publishing. However, you can’t choose that until you create the form, so let’s get down to the nitty gritty! Create a new form called ‘hReview’, choose ‘article’ from the type dropdown, and add the following code:


<div class="hreview">
  <h2 class="item"><txp:permlink class="fn"><txp:title /></txp:permlink></h2>
  <p><abbr class="dtreviewed" title="<txp:posted format="%Y%m%d" />"><txp:posted format="%B %e, %Y" / ></abbr>
  <span class="reviewer vcard">  by 
    <span class="fn"><txp:author /></span>
  </span>
  <txp:if_custom_field name="URL">
  <p><strong>Website:</strong> <a href="<txp:custom_field name="URL" />"  class="fn url" rel="bookmark"><txp:custom_field name="URL" /></a></p>
  </txp:if_custom_field>
   <div class="summary">
    <txp:excerpt />
   </div>
<div class="description">
    <p>Rating: <span title="<txp:custom_field name="Rating" />" class="rating"> <txp:custom_field name="Rating" /></span> out of 5</p>
<txp:article_image wraptag="p" class="photo" />
<txp:body/> 
</div>
</div>

A lot of this is self-explanatory. The review description is output wherever you put <txp:body />, the item name is output wherever you put <txp:title />. There are a few places where it’s probably worth talking through what’s going on.

Date

The txp tag @23.01.07 has an attribute “format” which allows you to customise the date using PHP’s strftime strings:

<abbr class="dtreviewed" title="<txp:posted format="%Y%m%d" />"><txp:posted format="%B %e" />, <txp:posted format="%Y" />

Doing this uses the published time information and displays in ‘human readable’ form:

< txp:posted format="%B %e, %Y" / >

as well as ISO for the title attribute:

<txp:posted format="%Y%m%d" />">

Handy if you also want to use Textpattern to display events in hCalendar format (which I’ll cover in another post).

Rating

Whatever number is entered into the Rating field is output in the title attribute as well as the text:

<p>Rating: <span title="<txp:custom_field name="Rating" />" class="rating"> <txp:custom_field name="Rating" /></span> out of 5</p>

There are other possibilities here, such as: class="rating star<txp:custom_field name="Rating" />" and then using image replacement to style the span with the resulting class name (star1, star2 etc.). The hReview creator suggests using HTML entities to display a star rating, for which we’d need to use the conditional tag <txp:if_custom_field>, e.g:

<txp:if_custom_field name="Rating" val="1">★☆☆☆☆</txp:if_custom_field>

This is what I used on the first review, but as Mr Oxton pointed out, this isn’t very ‘human readable’ to things like screenreaders, so I intend to implement the image replacement/class method above.

It’s a wee bit of sweat to set it up, but you have, you’ve got a form that can be called up anytime you want a review on your site to be marked up as a hReview!

Technorati TagsTags: , ,

03/12/05

Textpattern Notes: New Tag goodness

Back when Texpattern was still gestating, many plugins were written to fill holes in its templating options, but its come a long way since then. Every day I’m finding new tags that allow me to keep plugins down to a minimum.

If you haven’t already, you really need to bookmark these pages: Alphabetical Tag Listing and Attributes Cross Reference on the Textpattern wiki documention, called “TextBook”. This an amazing resource, especially if you adopted Textpattern back in the days when it had no documentation. There are lots of gems in here, so I thought I’d dig some out, in case they’re new to you as well.

Conditional Comments

I think the area where the 4.0-4.02 releases really shone were in the wealth of conditional tags. Here’s an example:

<txp:if_excerpt>
<blockquote>
&;ldquo; <txp:excerpt />”
</blockquote>
</txp:if_excerpt>

There are also conditional tags to test for categories, comments, whether comments are open, whether you’re viewing the last article and more. Check out all the tags that start with txp:if_ on the list. The section conditionals are very handy, as you can specify either a single section, or a range (make sure that you don’t have any spaces inbetween the section names, just commas). Here’s one from my templates:

<txp:if_section name="journal,destinations,archive">
...content...
</txp:if_section>

I use this one to output the correct submenu in each section. If you want to specify the homepage (or ‘default’ page as its known), leave the attribute blank like so:

<txp:if_section name="">
...content...
</txp:if_section>

To specify the homepage as part of a list, use a comma at the start:

<txp:if_section name=",journal,archives">
...content...
</txp:if_section>

Also Very Useful™, are the custom field conditionals. In my portfolio section, some of the entries are websites and have a URL associated with the information. This is done using a custom field (set up in preferences > advanced preferences) and used in the article form like this:

<txp:if_custom_field name="URL"> 
<a href="<txp:custom_field name="URL" />" title="Visit <txp:title />"><txp:article_image /></a>
</txp:if_custom_field>

This creates a link to the site around the main portfolio image.

Finally, to complete the usefulness, the devs have added a <txp:else /> conditional, to help keep code down. Here’s an example:


<p>
<txp:if_excerpt>

    <txp:excerpt />

    <txp:else />

    Sorry, I couldn't be bothered to write an excerpt...

    </txp:if_excerpt>
</p>

Permalinks & Single Tag mode

Until recently I was using the zem_link plugin to allow custom class names and title attributes on permalinks. It was one of the things that I didn’t like about TXP compared to Moveable Type – it outputted the XHTML for you. However, I found this on the description page for the permalink tag:

By default permlink returns only a very basic link, which doesn’t allow for customizing the link title, or adding a CSS class, etc. Using the tag in its Single Tag capacity opens up a lot more possibilities. For example, to have the permanent link have an HTML title attribute of the article’s title, and also apply a class to it named “orange”:

<a href="<txp:permlink />" title="<txp:title />" class="orange"><txp:title /></a>

Thats what I’ve been wanting! I had no idea that the tag could be used that way.

Offset

Another feature I missed from Moveable Type days was the ability to output a list of articles, offset by a specified number first. This is now part of the article tag attribute options:

<txp:article form="recent" sortby="Posted" sortdir="desc" offset="3" limit="5" />

I use this on my journal homepage, showing the last 3 posts in full, and then the 5 posts thereafter as just links. The list of previous articles can now exclude the last 3, as these are shown in full. For individual article pages however, we need to show all the articles, so of course I use conditional tags :

<txp:if_article_list> 
<txp:article form="recent" sortby="Posted" sortdir="desc" offset="3" limit="5" />

    <txp:else />

    <txp:article form="recent" sortby="Posted" sortdir="desc" limit="5" />
</txp:if_article_list>

Which neatly wraps it all up! One of the reasons I love Textpattern over other options so much, is its templating tags. The xml style makes so much sense, and easy to grasp.

Technorati TagsTags: , ,

04/10/05

Textpattern Notes: Comments revisited

In Textpattern notes parts 2, and 4 I explained how to hack TXP’s comments system to acheive certain effects. A lot has changed since then (especially with v4.0), and I need to update the methods. I’m now running TXP with no hacks whatsoever, and that’s a very good feeling™.

So lets run through those old hacks:

Step 1,4 & 5 – Changing the preview method, and integrating live Textile previews

I didn’t like having to preview the comment on a separate page (although this is a good spam-saving measure). I wanted to give users a live preview and allow them to submit their comment straight away.
These steps are now all combined within one plugin: nhn_livecommentpreview

It’s worth pointing out, that even with this safety feature removed, I only get comment spam at the rate of 1 every couple of months.

Step 2 – changing the comments to display as <div>’s rather than <li>’s

Simple. Go to Admin > Preferences, and under the ‘Comments’ section. click no to “Present comments as a numbered list?”. You’re now free to wrap your comment markup in whatever takes your fancy.

Step 3 – alternating background colours and sequential numbering

These steps can still be done with php, but for an easier life, I use ajw_comment_num (Allows for outputting current comment number) and ajw_comment_alt 0.3 (Alternates output based on even- or odd-numbered comments) by Andrew Waer

Step 6 – Adding an article link to the notification email

Now in TXP as of 4.01!

See how much easier it all is? Thanks to all the TXP and plugin developers for making my life so much easier.

With the next Textpattern notes, I’m going to look at some of the new tag goodness, especially the new conditional tags…

Technorati TagsTags: , ,

15/08/05

Now powered by Textpattern 4

They finally did it! Textpattern has just gone final, stable, and starts at version 4! Within in a minute, Hicksdesign was updated and running my favourite CMS. Another minute later, so was PimpMySafari.

I’ve tried, and keep on trying, other CMS’s and blogware, but keep coming back to Textpattern. Its well designed, lightweight in feel (but well endowed in features), fast to use, and most of all, logical. I still can’t imagine using anything else.

Dean, Zem, Kusor, Sencer and all the team – this is for you…

The celebratory Stinking Bishop Cheese

Technorati TagsTags: ,

26/05/05

Textpattern Notes 6: Overriding Forms

One of the most frequent questions I get asked about my Textpattern setup is how I do change content per article on the journal homepage. The majority of the time I have excerpts of each article with a link to read the full article, but sometimes I have very short articles that are shown in their entirety, and these just have the link for ‘Permalink’.

Its a feature of TXP that a lot of users I’ve come across don’t use. Next time you’re in your ‘write’ tab, look on the left under ‘advanced options’. That drop down called ‘override form’ will allow you to alter the display of the content per article.

Here’s how I use it:

I have a default article form for displaying posts on the journal front page. This outputs a title, link to full article and the excerpt. Here it is in cut-down form:
<h2><txp:permlink><txp:title /></txp:permlink> <txp:posted /></h2>
   <txp:if_article_list>
      <p><txp:permlink>Read the full entry</txp:permlink>
   <txp:excerpt />
</txp:if_article_list>

(The conditional comments <txp:if_article_list> mean these only show up on the homepage)

I also have another form, which uses similar markup, except that I use the whole body of the article, not just the excerpt. The link text changes to reflect this, so ‘Read full entry’ becomes ‘Permalink’. Here’s the cut-down version of that form:

<h2><txp:permlink><txp:title /></txp:permlink> <txp:posted /></h2>
   <txp:if_article_list>
      <p><txp:permlink>Permalink</txp:permlink>
   <txp:body />
</txp:if_article_list>

Then when I have just a small article to post, I just choose the relevant form from the ‘Overide form’ list. This overrides whatever you’ve set in your page template, not just if you’ve left it to use the ‘default’ article form. This isn’t really stretching its possibilities, and I’d love to know what, if any, ways you use this feature.

Technorati TagsTags: ,

16/04/05

Textpattern Notes 5 - Release Candidate 3

When RC3 came out a few months ago, I decided to hold off before I implemented it here. I knew it wouldn’t be straightforward to upgrade this time, as I have so many little hacks here and there, and several older plugins might cause problems. The final version v1 was supposedly only a week or so away, but of course that week has turned into months.

So spurred on by how easy it was to update Pimp My Safari to RC3, I finally decided to bite the bullet and upgrade sooner. RC1 to RC3 was a bit of a leap, but I imagine it’ll be a little smoother from here on.

These were the things that attracted me to upgrading:

  • File uploads – I can upload and categorise downloadables through the interface (in the same way as images), which wlll also keep track of the number of times its been grabbed. Superb.
  • No more placeholder files for sections – My root directory is now super clean and thats how I like it. (Its one of the things that irks me about Wordpress – having so many damn files in the root). This also means that adding new sections is even easier – all done via the interface. This makes it ideal for clients too. No more fiddling with .htaccess files.
  • Even less crufty URLS – No more ids in the URL, you can have dates, or just section/title as I have plumped for.
  • There is now an admin preference for whether comments are displayed in an ordered list or not. This was something I previously hacked to achieve, but now that it can be turned off easily, all the <div> styling goes into the comments form instead. Much easier! You can also put the php code into your page template and comment form to enable comment numbers and alternate row styling. Add the setup variables section to the page template (anywhere in the template above the <txp:article> tag)...
    <?
    // set up div class and numbering
    $class=odd;
    $cno=1;
    ?>
    ... and the code where the variables are changed to the bottom of the comment form…
    <?
    // change the values
    $cno=$cno+1;
    if("odd" == $class) {
    $class="even";
                }
    else {
    $class="odd";
                }
    ?>
    ...that way the initial values are set up, but will increment everytime TXP loops the comment form to display another comment.
  • admin plugins! This lets people like Rob Sable create wonderful admin enhancing plugins like QuikPik and Textarea Resizing.
  • Plenty of bug fixes, such as the one that really annoyed me, textile not working properly in excerpts.

There are also some features I haven’t delved into yet, such as sticky articles and the diagnostics panel, but lets hear it for these two new-for-RC3 stellar plugins:

glx_gravatar – Finally, no more hacking, a simple plugin to display Gravatars and show a default icon if the commenter doesn’t have a gravatar yet.

sgb_url_handler – This expands the new clean URL options by including elements such as catgegories! Now I can have /about/colophon/ rather than /about/?c=colophon! It also redirects other urls. So if you’ve used /blog/345/how-to-eat-cheese in the past, and you’ve changed your clean urls to be just /blog/how-to-eat-cheese, it still lets older URLS work! Superb!

Its not without a few problems of course. The low_nav plugin no longer works (this created back/next links within a category, as used in the portfolio), and I haven’t got around to re-hacking the commenting system to avoid the preview-before-submitting scenario. As such, I haven’t re-introduced live previews yet.

To summarise – RC3 is worth it, especially if you don’t rely on a lot of plugins or hacks. Textpattern is growing up, and becoming a fast and powerful CMS suitable to offer to clients, as well as blog use. There is another on the horizon that I’m keeping a keen eye on (I’m looking at you Symphony), but for me, there’s still nothing that beats Textpattern.

(Final wee note – I’ve also taken the opportunity to re-organise a little. Browser news is now found on the Browser Resources page, although the feed URL stays the same.)

Technorati TagsTags:

27/01/05

Textile previews in Ecto and MarsEdit

One of my bones of contention with Textpattern is that it still doesn’t support XML-RPC, allowing the use of a desktop weblog editor (although Dean has promised this for a while). However, thanks to Chris Mcleod, you can now get it up and working with Ecto and MarsEdit. I’ve had problems getting Textile previews to work in these apps, and wanted to share here the solutions in case anyone else has been in the same boat.

MarsEdit

Thanks to Brent Simmons and Brad Choate, who spent time finding a way to trick MarsEdit into thinking its using Markdown, but it is in fact using Textile. What follows are Brent’s instructions:

  1. Quit MarsEdit if it’s running.
  2. Go to the TextFilters folder at ~/Library/Application Support/MarsEdit/TextFilters/
  3. If you have a Markdown folder, delete it.
  4. Create a new folder named Markdown.
  5. Download Brad’s MT-Textile plugin.
  6. In the plugin folder—in extlib/Text/—you’ll find a file named Textile.pm. Put a copy of it in your /Library/Perl/ folder. (You may need to set execute permissions for Textile.pm. I did, though I’m not sure it’s necessary.)
  7. In the plugin folder—plugins/—you’ll find a file named textile2.pl. Copy it into ~/Library/Application Support/MarsEdit/TextFilters/Markdown/.
  8. Download and unzip this Markdown.pl file and drop into that same Markdown folder.
  9. Make sure Markdown.pl and textile2.pl have execute permission.
  10. Open Terminal and tell MarsEdit to always use Markdown for previews: defaults write com.ranchero.MarsEdit previewWithMarkdownAlways YES

Done! Its a little roundabout, but once setup, you can forget about it. Thanks Brent!

Ecto

With Ecto, the process is a lot more straightforward. When you add your Textpattern blog to Ecto, choose ‘Movable Type’ as the ‘system’, and then when you write posts in HTML mode, the Textile option becomes available in the options drawer, under ‘Formatting’ tab, in the ‘Format’ drop down menu. Now select ‘Make Default’ to make it the last time you need to do that.

format screenshot

As for which I will use for writing my blog posts, I’m not sure. I’m just enjoying in the fact that I can use both at the moment.

What these won’t do

Obviously there are a number of custom Textpattern options that neither of these apps will cater for. So far I’ve been using MarsEdit for the last 3 posts, and the only thing I have to do is go into my textpattern admin and turn on comments for each entry. Ecto doesn’t have this problem however, so I’m now giving that a spin. Maybe once Textpattern 1 final is released and gains populularity, there will be more support for Textpattern options in future versions of these apps.

Technorati TagsTags: , , ,

21/09/04

Textpattern notes part 4

A few more Textpattern odds and sods.

Finishing off the hacks to the comments.php file in Textpattern (see also TXP notes 3)textpattern-notes-part-3 is the introduction of a small feature from MovableType that I miss. When receiving email notifications of comments, they always had the relevant entry URL in them. You see the comment and want to reply, so just click the link to go straight there.

Here’s how to do this in TXP. In publish/comment.php find this line near the end (should be line 374 if you haven’t already hacked it):

<pre> $out = "Dear $RealName,\r\n\r\nA comment on your post on your post \"$Title\" was recorded. </pre>

Change it to this:
<pre> $out = "A comment on your post \"$Title\" (http://www.sitename.com/blog/$parentid/ ) was recorded. </pre>

Just change the URL to suit your site, and the parentid will add the relevant id into the URL. Incidentally, if you’re upgrading textpattern to the latest RC, and you’ve installed these hacks, then you just need to change 1 line of code in order to keep your customised version.

***

Integrating Textpattern with Photostack was another goal. I wanted to keep all my ‘include files’ (footer, navigation etc.) as forms within Textpattern, as this makes life so much easier. However, I also want to insert these in pages outside of Textpattern. To do this, open up the index.php file in Photostack, and change the small chunk of php to read:

<pre><?php // include Textpattern first include '/full/path/to/textpattern/config.php'; include $txpcfg['txpath'].'/publish.php'; ob_start('parse'); // Then pull in the photostack.php program. include("photostack.php"); // Load photostack. load('config.php'); ?> </pre>

And then all your Textpattern tags, such as <txp:output_form="header"> will parsed. This also works for static pages.

***

One of the shortcomings of Textpattern that I mentioned previously, no control over the XHTML output in permalink tags, has been solved by this excellent plugin by Zem. It allows attributes such as class and title to be specified. Nice.

***

Finally, I’ve only recently discovered what ‘override form’ in content>write>advanced options can be used for. I now have 2 forms for using with entries, a default one which only displays an excerpt on the main journal page (for long entries), and another which displays the full entry (for very short entries). I can then choose to override the default when posting or editing an entry for instance, when the entry is short. If the option to override form isn’t visible (under ‘Advanced Options’), the you may need to open up textpattern/lib/admin-config.php and change the ‘allow_form_override’ to equal 1.

Technorati TagsTags: , ,

29/08/04

Textpattern 2 months on

Two months after migrating to Textpattern, I thought I’d go over some of my thoughts since then. In particular, I’ve heard some people mention that they might migrate too, because it was ‘good enough for me’. So that no one blames for me for a move that they then regret, I’ll be honest about my Textpattern experience.

First of all, the things I’ve loved about using TXP so far:

  • Setting up new sections, links, RSS feeds and editing templates and entries are quick and easy.
  • I still love the XML style tags that it uses. I find these intuitive and pleasant to use (with a couple of exceptions – see below).
  • The Textpattern community are great at coming forward with useful plug-ins. They make it worthwhile.
  • The admin interface is just great. Simple and clean and delightful to use.
  • For some reason, I’ve posted far more regularly with TXP than I ever did with MT. I used to spend ages writing and re-writing posts, some would take months before I made them live. Whether this means more posts but with less quality, is for you to judge!

Its not all sunshine and tweety birds though, and there are few things that niggle me.

  • My main beef is that some (though not all) of the tags output the XHTML for you. E.g with MT, the permalink tag outputted only the link path, but Textpattern does the whole tag. So if you want control over it, you have to hack the textpattern php files. In particular, there were various unnesessary classes and small pieces of inline css that TXP generated. I’ve hacked a lot of these out, so I dread the next upgrade! As I understand it, Wordpress suffers from similar problems, and only MovableType really offers that flexibility.
  • It doesn’t have XML-RPC support (yet) so you can’t use something like Ecto to post entries. Especially as the next version of Ecto will include Textile previewing, my desire for this has grown. The admin interface is well designed, but drafts can get easily lost in the list of articles. With a weblog editor, Drafts are separated from the list of live articles, and previews are created live to save switching between ‘text’ and ‘preview’. Generally, a desktop client will always have the edge. In fact, I’ve missed this feature so much, that I’ve considered using Wordpress or reverting to MT for just the blog section. As I said previously, my reason for not going with Wordpress, was that it didn’t handle mutliple sections. Its excellent at what it does though – running a blog. The problems with php5 and Wordpress have prevented me testing this as a solution though. MT 3.1 also looks promising, with its support for dynamic pages solving my main MT bugbear – long rebuilds when fiddling with templates.
  • Navigating links in the admin interface can be painful if you have a lot. I use ‘links’ for my sidenotes, browser news and destinations links, and you don’t get the easy search facility that you get with articles.
  • I’d also like to see a way of getting clean url’s on categories built in.

Please don’t take this as a ‘woe is Textpattern’ statement, its far from it. – more of a report of my experience so far. Whether features like XML-RPC support will be added in the future or not is hard to say. Dean is a busy man who needs to earn a living (which doesn’t come from TXP!), and communications from him on where Textpattern is going is scant.

Update 20.9.04: Metaweblog support is going to be added in the near future, and a clearer vision of Textpattern’s future is emerging. I had a brief dalliance with Wordpress again – and confirmed my belief that it so isn’t the right tool for me. MT 3.1 looked improved, but Textpattern is most definitely where its still at for me.

Technorati TagsTags: ,

24/06/04

Textpattern notes Part 2

Please note the information in this entry is now superceded

For the second of my notes on Textpattern conversion, I’m going to cover just one subject : hacking the txp comment system.

Purpose of this hack:
Change the recorded comments to display as <div>’s rather than <li>’s, with alternating background colours and sequential numbering. Change the comment form to allow live previews to be used.

What you need to know first:
Upgrading Textpattern is a simple process, you simply upload all the new files (apart from the config.php file) and load _update.php in your browser to make sure all your database tables are updated. Its so quick. What I’m doing here is hacking the /textpattern/publish/comments.php file – a lot. This means that when you update, you’ll have your work cut out for you.

Still want to do it? Make a backup of that comments.php first, and then read on.

Background:
Textpattern, handles commenting a little differently to systems like Movable Type. A lot of the work is carried out behind the scenes, away from the page templates and forms, making personalisation harder. The comment form is laid out in presentation>forms>comment form, the display of comments is found in presentation>forms>comments. Then, as long as you have the <txp:comments_invite /> tag inside your article form (presentation>forms>default), Textpattern will add these elements together, along with the preview and remember details functions.

Step 1 – Change the existing preview method.

Dean Allen designed txp’s preview-first/submit-last routine to avoid spam flooding. This hack removes that safety net, and allows comments to be submitted directly, but I think this is less annoying for users. If we want to implement live comment previews, we have no choice – it has to go.

Justin Low worked out how to change this situation. Work through his instructions here, and you’re done.

Step 2 – changing the comments to display as <div>’s rather than <li>’s

I wanted to do this in order to have more control over my CSS. The ordered lists add comment numbers without any fancy coding, but restrict what markup can go inside the comment, and how much can be changed with CSS. Changing it to <div>’s gives that flexibility.

Still in /textpattern/publish/comments.php find the following code (around line 34):

f ($darr) {
$out.= '<ol>'.n;
$out.= formatComments($darr);
$out.= n.'</ol>';
}

and change it to:

if ($darr) {
$out.= '<div id="comment">'.n;
$out.= formatComments($darr);
$out.= n.'</div>';
}

then find this (around line 132):

$out .= n.t.'<li id="c'.$discussid.'" 
style="margin-top:2em">'.$temp.'</li>';

and change it to:

$out .= n.t.'<div id="c'.$discussid.'"
class="'.$class.'">'.$cno.' '.$temp.'</div>';

There are 2 php values in here, which we’ll use in the next step:

Step 3 – alternating background colours and sequntial numbering

Obviously, I can’t use the MTFlipFlop plug-in here, so I had to find a different solution. There’s also no tag in txp to output a comment number (because it used the ordered lists – which I removed!).

Once you’ve set up your 2 CSS classes for the alternating rows (I’ve used ‘odd’ and ‘even’), find the end of the php function – function formatComments($darr) (around line 75) and insert this code:

// set up div class and numbering
$class=odd;
$cno=1;

These are our 2 values, $class for inserting the div class, and $cno for the sequential comment number. Then, returning to the line where we changed the <li> to a <div>:

$out .= n.t.'<div id="c'.$discussid.'"
class="'.$class.'">'.$cno.' '.$temp.'</div>';

place this after it (but before the closing brace):

// change the values
$cno=$cno+1;
if("odd" == $class) {
$class="even";
            }
else {
$class="odd";
            }

This adds 1 to number count, and the decides whether the next time it loops, the div class should be odd or even. We’re almost there…

Step 4. Implementing Live Previews

The original post on how to do this can be found here. Now that we’ve done all the changes listed above, we can hard code the comments form.

In presentation>forms>comment form change this tag:

<txp:comment_name_input />

to:

<input type="text" id="name" name="name"  tabindex="1" 
onkeyup="ReloadNameDiv();" value="<?php echo $aname; ?>"  />

and then, back in comment.php, we need to change the <textarea> tag to:

$textarea = '<textarea name="message" id="message"
 onkeyup="ReloadTextDiv();" cols="1" rows="1"  tabindex="4">
'.htmlspecialchars($message).'</textarea>';

If users have already been on your site, chances are that a cookie has been set, allowing their details can be inserted automatically. By hard coding the name input, we have to do a bit more jiggery-pokery to get this working again. When we changed the <input> tag we added value="<?php echo $aname; ?>". This will output the cookie value into the text field, but we also need to grab the cookie values. To do that, place this somewhere above the form (I put this at the very top of my page template):

<?php 
  $aname = $_COOKIE['txp_name']; 
?>

(Thanks to Justin for that bit). Then, still on that page template, you just need to add the preview div at the bottom, after the <txp:article /> tag:

<txp:if_individual_article>
<div class="odd">preview :<a href="#" id="NameDisplay">
<?php echo $aname; ?></a>  on <?php $today=date("d.m.y");
print "$today"; ?>:
<div id="TextDisplay"></div>
</div>
</txp:if_individual_article>

The conditional tags stop the preview being displayed on the homepage where there are a number of articles, restricting it to a single entry page.

Step 5 – Textile preview

If you want to really finish things off, how about implementing Textile parsing in the preview? Jeff Minards javascript solution does exactly that, based on code by Stuart Langridge. Its genius!

You’re done at last. Have a drink, you deserve it!

Technorati TagsTags: , ,

22/06/04

Textpattern notes Part 1

As and when I get time, I’m going to post some more information about this site’s conversion over to Textpattern. I’m going to evangelise it until I’m blue in the face.

There were quite a few little tweaks I had to make, but here are just a few notes to be getting on with…

Clean URLs for the news feeds

Create your folder structure (such as /feeds/rss/) and place the following code in an index.php file in that last directory:

<?php
header('location: /?rss=1&section=journal');
?>

Just replace ‘rss’ for ‘atom’ if you need that feed too. I’ve also specified that the feed should come from my journal section, but you if you just run Textpattern as a blog you leave this out. Thanks to Drew McLellan of Allinthehead for this one.

Shortstats

In order to get Texpattern and Shaun Inman’s Shortstats working in harmony, I placed the shortstat include at the bottom of each of the section text files in the root. For example, in the ‘article’ file you would have :

<?php
include "./textpattern/config.php";
$s = "article";
include $txpcfg["txpath"]."/publish.php";
textpattern();
include($_SERVER["DOCUMENT_ROOT"]."/shortstat/inc.stats.php")
?>

Mixing hard coded and txp driven pages

In the about section, I needed to do something clever for the ‘about hicksdesign’ page, wheareas the colophon and the contact pages would essentially be just articles.

Using the If_category plug-in by Matthew Moss, I set up the ‘about’ section page to show the hard coded content if the category=hicksdesign, and just a plain article for the others:

<txp:mdm_if_category category="hicksdesign">
....hard coded content in here....
</txp:mdm_if_category>
<txp:mdm_if_category category="colophon,contact">
<txp:article limit="1" form="about" />
</txp:mdm_if_category>

This method is also used to alter the layout between the desktops page and the other downloads pages.

Technorati TagsTags: , ,

15/06/04

Textpattern migration

You made it! Were there any casualties? Is everyone else here?

To keep you on your toes, I’ve changed all my urls yet again. As hinted at in a previous entry, I’d decided to look into other CMS options that would give me better speed with no chugging (waiting for rebuilding). I tried out Pivot, Drupal, b2Evolution, Wordpress and Expression Engine, but in the end, Dean Allen won me over. Hicksdesign is now powered by Textpattern, instead of Movable Type.

I’m bound to get a lot questions as to why I didn’t decide on the trendy switchers choice – Wordpress. Its a fantastic CMS system, and it was a very close call, but it doesn’t lend itself to multiple sections like Textpattern. Sure, I can install WP several times (and installation is a quick process) but there are seven ‘blogs’ that make up this site, and thats seven to upgrade everytime there’s an update. Textpattern is naturally geared towards managing an entire site with one installation, and that really appealed to me. It lets me do everything very fast, and its admin interface is well designed and pleasing to use.

There was also a indescribable something about Textpattern. It just clicked with me and I enjoyed using it, even if I didn’t fully understand how to do what I wanted to do at first. Going back to Movable Type afterwards felt unfulfilling – so migration was going to happen. Textpattern is by no means as feature-packed as Wordpress, but the few minor features/abilities that I needed are either served by plug-ins or are coming in future versions. There are few niggles too, no system (other than maybe a home-made solution) is perfect, but these weren’t enough to me off.

The migration couldn’t have been done without the ever patient and helpful folks of the Textpattern forum, who put up with my endless poking and interrogation. Responses to my queries were either “find it here..” or “Textpattern doesn’t do that, I’ll write a plugin for it though…”. Like the elves and the shoemaker, I’d wake to find another plug-in had been made. Getting to grips with Textpattern’s tag system was made easy thanks to Kusors Tag Manual . This was another score against WP actually – it uses an XML style tag system which I found more intuitive.

Some notes about the migration:

  • The whole site is now powered by Textpattern. When I used MT, only certain sections were driven by the CMS, now its all of it. All apart from…
  • The playlist. Its lost its XML feed, and Instead of showing the last 6 albums purchased, it now displays the last 6 played, via the wonder of Michael Simmons’ excellent iTunesWatcher. I’d used version 1 previously, and it just gets better. A very special thankyou to Michael for creating the custom module for displaying the my last 6 covers.
  • The articles section is gone. These are now incorporated into the journal for simplicity.
  • You can now see what I’m eating, at any time of the day. You lucky people.
  • I was planning a redesign of the journal section to coincide with the new CMS, but this was too much in one go. More on that later…

So here we are. There are still a few loose ends to tie up, but everything is pretty much here, with a whopping great .htaccess file to help people find their way here. Please bear with me while I iron out the creases…

Technorati TagsTags:

Elsewhere

The Rissington Podcast - weekly shenanigans with Jon Oxton

Hicksmade - unique handmade goods by Leigh Hicks width=

archives

love

Brit Pack: A proud member I love Omniweb Coda Segment Publishing I buy my type from Veer The Forgiveness Project