ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Next 3 and previous 3postings possible?

December 04, 2008 7:45am

Subscribe [3]
  • #1 / Dec 04, 2008 7:45am

    timur

    1 posts

    I’ve got a website with a variety of weblogs (‘news’, ‘events’ and ‘directory’) - in the news directory I would like to be able to do the following:

    When someone views a news article, at the bottom of the article I would like to be able to show the titles of the previous 3 news articles and the next 3 news articles.

    Obviously if there are less than 3 news articles (for exampel someone views the second most recent posting, there is only one newer one).

    I’ve tried doing this using {entry_id} and {start_on} etc, but I don’t seem to have been able to find a solution. Any ideas?

    Many thanks.

    Timur

    PS:

    An Example of what I mean…

    Article 1 (first article)
    Article 2
    Article 3
    Article 4
    Article 5
    Article 6
    Article 7
    Article 8
    Article 9
    Article 10 (last article)

    Viewing article 7 for example would result in showing:

    Previous posts:
    Article 6
    Article 5
    Article 4

    Next posts:
    Article 8
    Article 9
    Article 10

  • #2 / Feb 06, 2009 6:42pm

    EpicSoft

    64 posts

    From my index

    {embed="site/prev_next" entrydate_sql="{entry_date}" }

    Code from “site/prev_next”

    Prev 3
    <table border="0" cellspacing="8" cellpadding="8">
    {exp:query sql="SELECT * FROM `exp_weblog_titles` WHERE weblog_id=2 and `entry_date` < {embed:entrydate_sql} ORDER BY `entry_date` DESC LIMIT 3"}
      <tr>
        <td><a href="http://{site_link}show/{entry_id}/">{title}</a></td>
        <td>{entry_date format='%Y-%m-%d %H:%i'}</td>
      </tr>
    {/exp:query}
    </table>
    Next 3
    <table border="0" cellspacing="8" cellpadding="8">
    {exp:query sql="SELECT * FROM `exp_weblog_titles` WHERE weblog_id=2 and `entry_date` > {embed:entrydate_sql} ORDER BY `entry_date` ASC LIMIT 3"}
      <tr>
        <td><a href="http://{site_link}show/{entry_id}/">{title}</a></td>
        <td>{entry_date format='%Y-%m-%d %H:%i'}</td>
      </tr>
    {/exp:query}
    </table>

    I Don’t have a lot of entries but the above seems to works for me.
    Hope this works for you.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases