Added Next, Previous Article & Home navigation
This commit is contained in:
parent
43d8c3a7ff
commit
a214b9e716
4 changed files with 58 additions and 8 deletions
|
@ -19,4 +19,8 @@ module BlogPostsHelper
|
|||
html += '</nav></section>'
|
||||
html.html_safe
|
||||
end
|
||||
|
||||
def next_or_previous?(post)
|
||||
post.next.present? or post.prev.present?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,26 +10,40 @@ class BlogPost < ActiveRecord::Base
|
|||
|
||||
has_friendly_id :title, :use_slug => true
|
||||
|
||||
default_scope :order => "published_at DESC"
|
||||
|
||||
if Rails.version < '3.0.0'
|
||||
named_scope :by_archive, lambda { |archive_date| {:conditions => ['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]} }
|
||||
named_scope :by_archive, lambda { |archive_date| {:conditions => ['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month], :order => "published_at DESC"} }
|
||||
else
|
||||
scope :by_archive, lambda { |archive_date|
|
||||
where ['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]
|
||||
where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]).order("published_at DESC")
|
||||
}
|
||||
end
|
||||
|
||||
if Rails.version < '3.0.0'
|
||||
named_scope :all_previous, :conditions => ['published_at <= ?', Time.now.beginning_of_month]
|
||||
named_scope :all_previous, :conditions => ['published_at <= ?', Time.now.beginning_of_month], :order => "published_at DESC"
|
||||
else
|
||||
scope :all_previous, where(['published_at <= ?', Time.now.beginning_of_month])
|
||||
scope :all_previous, where(['published_at <= ?', Time.now.beginning_of_month]).order("published_at DESC")
|
||||
end
|
||||
|
||||
if Rails.version < '3.0.0'
|
||||
named_scope :live, lambda { {:conditions => ["published_at < ? and draft = ?", Time.now, false]} }
|
||||
named_scope :live, lambda { {:conditions => ["published_at < ? and draft = ?", Time.now, false], :order => "published_at DESC"} }
|
||||
else
|
||||
scope :live, lambda { where( "published_at < ? and draft = ?", Time.now, false) }
|
||||
scope :live, lambda { where( "published_at < ? and draft = ?", Time.now, false).order("published_at DESC") }
|
||||
end
|
||||
|
||||
if Rails.version < '3.0.0'
|
||||
named_scope :previous, lambda { |i| { :conditions => ["published_at < ?", i.published_at], :order => "published_at DESC", :limit => 1 } }
|
||||
named_scope :next, lambda { |i| { :condtions => ["published_at > ?", i.published_at], :order => "published_at ASC", :limit => 1 } }
|
||||
else
|
||||
scope :previous, lambda { |i| where(["published_at < ?", i.published_at]).order("published_at DESC").limit(1) }
|
||||
scope :next, lambda { |i| where(["published_at > ?", i.published_at]).order("published_at ASC").limit(1) }
|
||||
end
|
||||
|
||||
def next
|
||||
self.class.next(self).first
|
||||
end
|
||||
|
||||
def prev
|
||||
self.class.previous(self).first
|
||||
end
|
||||
|
||||
def live?
|
||||
|
|
|
@ -31,6 +31,13 @@
|
|||
<span class="st_sharethis" displayText="ShareThis"></span>
|
||||
<% end %>
|
||||
</article>
|
||||
<% if next_or_previous?(@blog_post) -%>
|
||||
<nav id="next_prev_article">
|
||||
<%= link_to raw(truncate(@blog_post.next.title) + " »"), @blog_post.next, :class => 'next' if @blog_post.next.present? %>
|
||||
<%= link_to 'Blog Home', blog_root_path, :class => 'home' %>
|
||||
<%= link_to "« ".html_safe + truncate(@blog_post.prev.title), @blog_post.prev, :class => 'prev' if @blog_post.prev.present? %>
|
||||
</nav><!-- /next_prev_article -->
|
||||
<% end -%>
|
||||
<% if BlogPost.comments_allowed? %>
|
||||
<aside id="comments">
|
||||
<h2><%= t('.comments.title') %></h2>
|
||||
|
|
|
@ -23,3 +23,28 @@
|
|||
padding-left: 25px;
|
||||
background: url('/images/refinerycms-blog/rss-feed.png') no-repeat;
|
||||
}
|
||||
#next_prev_article{
|
||||
overflow:hidden;
|
||||
margin:10px 0;
|
||||
position:relative;
|
||||
height:30px;
|
||||
}
|
||||
#next_prev_article a{
|
||||
display:block;
|
||||
width:33%;
|
||||
height:30px;
|
||||
line-height:30px;
|
||||
position:absolute;
|
||||
top:0;
|
||||
}
|
||||
#next_prev_article a.prev{
|
||||
left:0;
|
||||
}
|
||||
#next_prev_article a.home{
|
||||
left:33%;
|
||||
text-align:center;
|
||||
}
|
||||
#next_prev_article a.next{
|
||||
text-align:right;
|
||||
right:0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue