3

So, i've got a page where it shows 2 news entries. Then there is a link that when clicked, loads in via ajax more entries until they run out.

My template that gets pulled in via ajax looks like this:

    {exp:channel:entries
      channel="news"
      disable="categories|category_fields|member_data|trackbacks"
      dynamic="no"
      limit="2"
      paginate="bottom"
      orderby="date"
      sort="desc"
    }
     <h1>{title}</h1>
{content}
          {paginate}
            {pagination_links}
                {next_page}          
                    <li class="example"><a href="{pagination_url}" title="example" class="news-ajax-link">More news &rarr;</a></li>
                    {/next_page}
            {/pagination_links}
        {/paginate}

      {/exp:channel:entries}

Which works and is fine, but, how do i get it to not pull in the first two articles (as they are already on the original page) but still be able to keep calling that page to load in more entries normally?

3 Answers 3

0

Would the offset param set to 2 work?

http://ellislab.com/expressionengine/user-guide/modules/channel/channel_entries.html#offset

2

You just need to add entry_id="not 45|46" if 45 and 46 were your entry ids for those two.

I have done this before with jQuery. You just need to bring those two entry ids over to your load. You could probably add them easily via the segments.

Brad

2
  • Well, that would work but only in the scenario where those news items never got deleted, so it's not flexible enough. What i did, was on the existing page, i put the "load more content" link in between paginate links so the link was site.com/news/P2 or whatever, then i used some js to modify that link to be site.com/ajax_news/P2 so that it loaded the subsequent news items in properly. The beauty of this, is without js enabled, it still works in the way it should. Commented Nov 30, 2012 at 8:41
  • Sounds like a good solution, John. You should post your answer with the template code and jQuery/JS and accept it!
    – Alex Kendrick
    Commented Nov 30, 2012 at 13:37
2

I think these suggestion would work but (and correct me if I'm wrong) I think each subsequent click should returns 2 more entries not from any of the other prior results. So each click needs to return 2 more results that get added to the results from ALL previous requests. If that is the case then in Nate's offset solution you'd need to track how many times the link was clicked and adjust the offset up each time. 1st click offset = 2, second offset = 4, etc. A similar trick would be required for Parscale's solution. not 45|46 on the second request which may return ID 78 and 79. The next (3rd) request would need to set entry_id="not 45|46|78|79" to avoid picking up 45 and 46 again. Or am I misunderstanding the question?

1
  • Adam you bring up a good point! I wonder if some sort of increment plugin could be used to offset in steps of two. For example using something like this: devot-ee.com/add-ons/increment and it's tag in the offset param itself (might have to beat parse order via Stash or similar) - at the same time I also wonder how that would work with Ajax and if every "ajax call" hit to that template would trigger the increment or not.
    – Natetronn
    Commented Nov 29, 2012 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.