murklinstest (murklinstest) wrote,
murklinstest
murklinstest

Style Contest: Tag Filtered Recent Entries as Index Page

Show the Recent Entries page in more of an index style, with just excerpts of the entry text, not full entries, but only when viewing a tag subset of the entries.

Paste this function into your theme layer, altering the blue configuration variables to suit you.

# On the Recent Entries page, when filtering by tag, use an index style, not full entries #
function RecentPage::print_body() {

########## Configure the Excerpting ##########

# Specify the termination character
var string stopchar = "^";

# Specify whether you want the termination character displayed in the excerpt or not
var bool showstopchar = false;

# Specify how many characters of the entry to search for a termination char before giving up and not including an excerpt
var int cutoff = 500;

###############################################

    if ($.nav.backward_url != "" or $.nav.forward_url != "") {
        println """<p class="content-nav">""";
        if ($.nav.backward_url != "") {
            println """<a href="$.nav.backward_url">"""+get_plural_phrase($.nav.backward_count, "text_skiplinks_back")+"</a>";
        }
        if ($.nav.backward_url != "" and $.nav.forward_url != "") {
            print " | ";
        }
        if ($.nav.forward_url != "") {
            println """<a href="$.nav.forward_url">"""+get_plural_phrase($.nav.forward_count, "text_skiplinks_forward")+"</a>";
        }
        println """</p>""";
    }

    # This is a tag-filtered view, so show an index of the entries
    var bool done = false;
    if ((size $this.data_links_order) > 0) {
        if ($this.data_link{"rss"}) {
            var Link dlink = $this.data_link{"rss"};
            if ($dlink.url->contains("?tag=")) {                
                print """<div class="entry"><div class="entry-content"><div class="entry-body"><ul class="entry-index">""";
                foreach var Entry e ($.entries) {
                    
                    print "<li>";
                    if ($e.poster.username != $e.journal.username) {
                        $e.poster->print(); " ";
                    }
                    "$e.security_icon";
                    print """<span class="index-link">""";
                    if ($e.subject != "") {
                        """ <a href="$e.permalink_url">$e.subject</a>""";
                    } else {
                        print """ <a href="$e.permalink_url" style="font-style: italic;">$*text_nosubject</a>""";
                    }
                    print "</span>\n";

                    if ($e.text_must_print_trusted == false) {
                        var string t = $e.text->substr(0, $cutoff);
                        var string summary = "";
                        foreach var string c ($t) {
                            if ($c == $stopchar) {
                                break;
                            }
                            $summary = $summary + $c;
                            continue;
                        }
                        # Stop char never found, so assume this entry not formatted for excerpting
                        if ($summary == $t) {
                            $summary = "";
                        }
                        if ($showstopchar and ($summary != "")) {
                            $summary = $summary + $stopchar;
                        }
                        print """<div class="index-summary">$summary</div>\n""";
                    }

                    print """<div class="index-meta">[ """;
                    if (size($e.tags) > 0) {
                        var int tcount = 0;
                        print """<span class="index-tags"><span class="index-tags-title">tags:</span> """;
                        foreach var Tag t ($e.tags) {
                            print """<a rel="tag" href="$t.url">$t.name</a>""";
                            $tcount++;
                            if ($tcount != size $e.tags) {
                                print ", ";
                            }
                        }
                        """</span> <span class="index-sep1">||</span> """;
                    }                    
                    var string edate = """<span class="index-date">""" + $e.time->date_format("%%yyyy%%-%%mm%%-%%dd%%") + """</span> <span class="index-sep2">|</span> <span class="index-time">""" + $e.time->time_format("short");
                    print $edate;
                    if ($e.comments.show_readlink) {
                        print """ <span class="index-sep2">|</span> <span class="index-comments">""";                        
                        $e.comments->print_readlink();
                        print "</span>";
                    }
                    " ]</div>\n";                   
                    "</li>\n";
                }
                print "</ul></div></div></div>";
                $done = true;
            }
        }
    }

    if ($done == false) {
    foreach var Entry e ($.entries) {
        if ($*opt_datehead and $e.new_day) {
            print """<h2 class="date-header">"""+$e.time->date_format("med")+"""</h2>""";
        }

        # Print the entry
        $this->print_entry($e);
        if ($e->viewer_sees_ebox()) {
            """<div align="center" style="margin-bottom: 20px;">""";
            $e->print_ebox();
            "</div>";
        }
    }
    }


    if ($.nav.backward_url != "" or $.nav.forward_url != "") {
        println """<p class="content-nav">""";
        if ($.nav.backward_url != "") {
            println """<a href="$.nav.backward_url">"""+get_plural_phrase($.nav.backward_count, "text_skiplinks_back")+"</a>";
        }
        if ($.nav.backward_url != "" and $.nav.forward_url != "") {
            print " | ";
        }
        if ($.nav.forward_url != "") {
            println """<a href="$.nav.forward_url">"""+get_plural_phrase($.nav.forward_count, "text_skiplinks_forward")+"</a>";
        }
        println """</p>""";
    }
}
Tags: code:tag-filtered index page, layout:style contest
Subscribe

  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments