Matt Legend Gemmell Modesty is Lying

Mac OS X Cocoa and iPhone Development Services available at Instinctive Code.
Favorites icon
Favorites for iPhone
Speed-dial with style.
Mac OS X Cocoa and iPhone Developer for hire

Other Pages

Categories

Posted
26 February 2003 @ 7am

Categories
General

Tags

“Read More” Implemented

Another day, another PHPosxom hack! This time, we’ve got “Read More” functionality;
a useful way to stop your main page becoming huge if you post a lot, or if you tend
to post longer articles (like me).

This one is actually more of an enhancement than a hack, since you can put it
in your “_flav” file - no need to edit PHPosxom itself. For more info, and the code,
read on.

First of all, welcome to the rest of this article! If you’re impatient (and/or comfortable
with basic PHP), you can skip ahead and just grab the code.

Still here? Then let’s go through the basic steps you need to follow in order to get the
“Read More” functionality in your PHPosxom blog. Note that these instructions assume that
you’re using a “_flav” file to format your blog. If you’re just using PHPosxom “as-is”, you
have the choice of either making a _flav file before proceeding, or if you’re happy with PHP
then it’s very easy to slightly hack this code to integrate it into PHPosxom itself. I’ll leave
that as an exercise for the reader.

 

1. First, make sure you have the code.

2. Copy the whole readmore function into the top of your appropriate _flav file (probably “default_flav”).

The whole readmore function is everything between (and including) these lines:


function readmore($text, $path) {

   …

   # We’re at a permalink, so show all $text.
   return $text;
}

You need to put it just after the <?php line at the top of your _flav file (on the next line).
If you like, you can also edit the readmore function to choose your own more-markers, links, and the actual text
of “Read More” links.

3. In the storyBlock section of your _flav file, change $text to readmore($text, $path).

4. Go and edit your posts to insert appropriate more-markers (the default is <!--more-->).

 

That’s it. Your blog now has “Read More” links! The behaviour is simple:

  • If the page you’re viewing is a permalink, the full content is displayed.
  • Otherwise, if an appropriate more-marker is found, only the content before the marker is shown, and a “Read More” link is added.
  • If you want to force the full content to be shown in certain situations, you can add a more=1 parameter to the page’s URL.

Needless to say, the code (and this “documentation”) is free for everyone - do what you like with it.
Feel free to send questions, comments, requests and improvements my way.


No Comments Yet


There are no comments yet. You could be the first!

Leave a Comment

TrackBacks implemented Getting there…