Welcome to Geeklog, Anonymous Thursday, November 28 2024 @ 07:34 am EST

Geeklog Forums

Creating your own "read more" text


Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Here's an interesting little problem: How do you make the text for the "read more" link (from the index page, when a story has a non-empty body text) dynamic? For example, the Serendipity blog software has "read more" links that read

Continue reading "story title here"

How would you do that with Geeklog?

Here's the solution. It requires Geeklog 1.4.1, which now calls CUSTOM_templateSetVars (in lib-custom.php) for every story. It also makes use of a tiny little feature of our template library that we don't use anywhere else in Geeklog: You can request the value of a template variable.

Text Formatted Code
function CUSTOM_templateSetVars ($templatename, &$template)
{
    if (($templatename == 'featuredstorytext') || ($templatename == 'storytext') || ($templatename == 'archivestorytext')) {
        if (strpos ($_SERVER['PHP_SELF'], 'article.php') === false) {
            $title = $template->get_var ('story_title');
            if (!empty ($title)) {
                $readmore = $template->get_var ('lang_readmore');
                if (empty ($readmore)) {
                    $template->set_var ('my_readmore', '');
                } else {
                    $template->set_var ('my_readmore', 'Continue reading "' . $title . '"');
                }
            }
        }
    }
}

So the trick is to call get_var for the story's title and the "lang_readmore" variable. The latter is not set when the story's body text is empty. So if that's the case, we don't set the "my_readmore" variable. Otherwise, we use the title to build the link.

And in the story templates, we simply use this then:
Text Formatted Code
{start_readmore_anchortag}{my_readmore}{end_readmore_anchortag}

This entires construct disappears when the story's body text is empty. Otherwise, we get a story link à la Serendipity.

bye, Dirk
 Quote

Status: offline

Don

Forum User
Full Member
Registered: 06/09/04
Posts: 153
That's pretty slick, Dirk! Works like a charm. Thanks!

- D
 Quote

All times are EST. The time is now 07:34 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content