Matt Gemmell

My new book CHANGER is out now!

An action-thriller novel — book 1 in the KESTREL series.

★★★★★ — Amazon

"Read More" Implemented

general 1 min read

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 <a href="http://www.scotlandsoftware.com/blog/meta/phposxom_read_more.txt">grab the code</a>.



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.



&nbsp;

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 <code>readmore</code> 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 <code>&lt;?php</code> line at the top of your _flav file (on the next line).
If you like, you can also edit the <code>readmore</code> 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-->).

&nbsp;



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.