ebullient·works

[ About · Archive ]

TXP Hack: Using TXP Excerpts like MT

One of the things I used heavily in MT was the body/extended body trick. I wanted to continue that with Textpattern, but it involved some hacks to how TXP handles excerpts.

[Based on Textpattern 1.0rc1]

  1. Add an additional column, Excerpt_html, to the textpattern table so that Excerpt has the same behavior as the body (original textile is saved, with the html result in the _html column).
    • Change to txpsql.php:
            --- txpsql.php  23 Jan 2005 02:40:40 -0000      1.1
            +++ txpsql.php  6 Feb 2005 17:44:33 -0000       1.2
            @@ -19,6 +19,7 @@
               `Body` text NOT NULL,
               `Body_html` text NOT NULL,
               `Excerpt` mediumtext NOT NULL,
            +  `Excerpt_html` mediumtext NOT NULL,
               `Image` varchar(255) NOT NULL default '',
               `Category1` varchar(128) NOT NULL default '',
               `Category2` varchar(128) NOT NULL default '',
        
    • Change to _update.php:
            --- _update.php 23 Jan 2005 02:40:40 -0000      1.1
            +++ _update.php 6 Feb 2005 17:43:05 -0000       1.2
            @@ -50,6 +50,10 @@
                    if (!in_array('Excerpt',$txp)) {
                            safe_alter("textpattern", "add `Excerpt` mediumtext not null after `Body_html`");
                    }
            +    
            +       if (!in_array('Excerpt',$txp)) {
            +               safe_alter("textpattern", "add `Excerpt_html` mediumtext not null after `Excerpt`");
      
            +       }
        
    • In order to have _update.php run (to add the column to an existing textpattern table), temporarily change $thisversion in textpattern/index.php to '0'. _update.php will run the next time you do anything with textpattern/index.php. Once it runs, return $thisversion to its original value.
  2. Make textpattern/include/txp_article.php store the raw textile text and the html formatted text separately. Also, since I am used to writing the excerpt and then the body, I moved the excerpt box above the body box on the entry form. This diff is a little more involved, I've attached it here.
  3. Finally, we need to make textpattern/publish.php display Excerpt_html instead of Excerpt. The diff is here.

For the full article display, use <txp:excerpt /> and <txp:body />. To show just the excerpt, use <txp:excerpt />.

I selectively show a "[more]" link based on whether or not there is additional body text. If an entry is really short, sometimes there is only an excerpt. I created my own plugin to do this, and it looks like this:

function elh_article_more($atts)
{
    global $thisarticle;
    if (is_array($atts)) extract($atts);

    $body = $thisarticle['body'];
    if ( !preg_match("/w/", $body) )
        return '';

    $link = '<a href="'.$thisarticle['permlink'].'">more</a>';

    return '<div class="more">['.$link.']</div>';
}

Have Fun!