Created
February 5, 2009 03:03
-
-
Save will/58520 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# will leinweber's lib/helpers.rb for webby | |
def first_post | |
all_posts.first | |
end | |
def next_post(post) | |
all_posts[ all_posts.rindex(post) - 1 ] | |
end | |
def prev_post(post) | |
all_posts[ all_posts.rindex(post) + 1 ] | |
end | |
def all_posts | |
@all_pages ||= @pages.find( :limit => :all, | |
:draft => nil, | |
:sort_by => "created_at", | |
:blog_post => true, | |
:reverse => true | |
) | |
end | |
def other_posts(post=nil) | |
post ||= @page | |
npost = next_post(post) | |
ppost = prev_post(post) | |
html = "<div class='otherposts'><ul>" | |
html += "<li> Next Post: #{link_to_post npost}</li>" if npost unless post == first_post | |
html += "<li>Previous Post: #{link_to_post ppost }</li>" if ppost | |
html += "</ul></div>" | |
end | |
def link_to_post(post) | |
link_to post.title, post.url | |
end | |
def find_post(title) | |
@pages.find( :limit => 1, :title => title).first | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment