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.

Channel listing with pagination and single entry on the same page

April 30, 2012 5:48am

Subscribe [1]
  • #1 / Apr 30, 2012 5:48am

    Elliot Lewis

    49 posts

    A section of a site I’m building has a 2 column layout.
    On the left is a list of 5 recent news entries from the news channel. Just the titles and date.
    Below it is pagination to navigate through all the news.

    Nav:

    {exp:channel:entries 
      channel="news"
      orderby="date" 
      sort="desc"
      limit="5" 
      dynamic="yes"
      pagination="bottom"
      disable="categories|member_data|trackbacks"
      }
       
       <li>
        <h2><a href="http://{url_title_path=">{title}</a></h2>
    <p>    <date>{entry_date format="{global:date_short}"}</date><br />
       </li><br />
        <br />
       {if count==total_results}</ul></nav>{/if}<br />
       <br />
       {paginate}<br />
        {pagination_links}<br />
         <ul class="pagination"><br />
          {!-- Paginate code --}<br />
        {/pagination_links}<br />
       {/paginate}</p>
    
    <p>  {/exp:channel:entries}

    On the right is the news story, on the same page.

    Entry:

    {exp:channel:entries 
       channel="news"
       limit="1"
       dynamic="yes"
       disable="categories|member_data|pagination|trackbacks"
       }
    
       <date>{entry_date format="{global:date_short}"}</date>
       <h2>{title}</h2>
    <p>   {body}<br />
            <br />
      {/exp:channel:entries}

    All nice and straight forward.

    On the first page load, http://example.com/news/ the page loads as required. The latest 5 stories on the left and the latest story in full on the right.

    Clicking the next entry down in the nav goes to http://example.com/news/second-news-entry/. The Story loads but because dynamic is yes for the left nav, only the second news entry loads in the nav, as expected. To stop the Nav channel:entries tag using the using the url I’ve set dynamic=“no”.

    Then any of the 5 entries in the nav go to the correct entry url and each show the latest 5 news entries on the left.

    But now because the left channel:entries tag isn’t using the url the pagination doesn’t work. http://example.com/news/P5 is ignored.

    How can this page be built with both channel:entries tags using the url?

  • #2 / Apr 30, 2012 4:55pm

    Dan Decker

    7338 posts

    Hi Elliot,

    I’m sorry you are having trouble getting this to behave!

    What version of ExpressionEngine are you using? There is a bug in the current version where pagination is disrupted with dynamic=“no” Without the bug, ExpressionEngine still honors pagination despite the dynamic parameter. The fix seems to be to declare all three values for the paginate= parameter:

    {exp:channel:entries 
      channel="news"
      orderby="date" 
      sort="desc"
      limit="5" 
      dynamic="no"
      pagination="bottom|top|both"
      disable="categories|member_data|trackbacks"
      }

    Give that a shot and let me know your results.

    Cheers,

  • #3 / Apr 30, 2012 5:54pm

    Elliot Lewis

    49 posts

    EE v2.3.1

    This is sounding promising. I didn’t think what I’m trying to achieve was possible. Can 2 channel:entries tags on the same page use the same url?
    If an entries tag is set to dynamic=“no” should the pagination still work? What url would I expect?
    On the index page would it be:
    http://example.com/news/P5

    And on an entry page:
    http://example.com/news/second-news-entry/P5

    I’ve tried pagination=“bottom|top|both” and the pagination links get very confused. On the index page the links look correct:
    http://example.com/news/P5

    On page 2 the next_page link becomes:
    http://example.com/news/P5/P5

  • #4 / May 01, 2012 2:57pm

    Dan Decker

    7338 posts

    Hi Elliot,

    I don’t know personally that it’s *possible*, but I’m certain it’s been done before.

    Once solution may be to consider an AJAX implementation for the sidebar, just to sidestep the URL issue altogether.

    But, your original question in the title, I looked back over again. Can you try this:
    For your paginated sidebar:

    {exp:channel:entries 
      channel="news"
      orderby="date" 
      sort="desc"
      limit="5" 
      dynamic="no"
      pagination="bottom"
      disable="categories|member_data|trackbacks"
      }
       
       <li>
        <h2><a href="http://{url_title_path=">{title}</a></h2>
    <p>    <date>{entry_date format="{global:date_short}"}</date><br />
       </li><br />
        <br />
       {if count==total_results}</ul></nav>{/if}<br />
       <br />
       {paginate}<br />
        {pagination_links}<br />
         <ul class="pagination"><br />
          {!-- Paginate code --}<br />
        {/pagination_links}<br />
       {/paginate}</p>
    
    <p>  {/exp:channel:entries}

    and for the entry

    {exp:channel:entries 
       channel="news"
       limit="1"
       disable="categories|member_data|pagination|trackbacks"
       }
    
       <date>{entry_date format="{global:date_short}"}</date>
       <h2>{title}</h2>
    <p>   {body}<br />
            <br />
      {/exp:channel:entries}

    What you will want to do though is supply some identifying information to the second entries loop. Like a url_title or entry_id parameter.

    Sorry for drawing this out, but it took a double take to get a grip on exactly what you are trying to do here 😊

    Cheers,

  • #5 / May 02, 2012 11:12am

    Elliot Lewis

    49 posts

    dynamic="yes"

    on the second entries tag was an overhang from testing yes and no. As the default is yes, it has no effect removing it.

    I don’t know personally that it’s *possible*, but I’m certain it’s been done before.

    If you’re not sure if it’s possible, how are you sure it’s been done before? I too am surprised in the time I’ve been using EE I’ve not developed a site with this layout and I’m also surprised that other devs haven’t encountered this issue. But looking at how the channel:entries tag works I don’t know how this can be achieved.

    Because the site is live I had no option but to find a solution, so I’ve built an addon to create my own pagination for the channel module.

    Live site: http://hopfarmfestival.com/news

    I’ve added some AJAX to load in just the nav pagination, so turn JS off to view the urls.

    I could make this available on GitHub if anyone needs it, it’s very specific for what I needed to achieve though.

  • #6 / May 02, 2012 5:31pm

    Dan Decker

    7338 posts

    Hi Elliot,

    I too am surprised in the time I’ve been using EE I’ve not developed a site with this layout and I’m also surprised that other devs haven’t encountered this issue.

    That very reason was why I suspected it had been done before. Because you can’t have been the first to try and sort this out! The lack of chatter on the subject just led to an assumption, and well, we know how that goes.

    I could make this available on GitHub if anyone needs it, it’s very specific for what I needed to achieve though.

    I encourage you to do just that! I would be interested in seeing it, and I bet it wouldn’t take much to make it play nice for other scenarios.

    As little as I helped here, is there anything else I can assist you with?

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases