3

For one of my channels there is no template for displaying a single entry. Entries are only ever displayed in a list on a landing page, which is continued on the paginated sub-pages, like:

http://website.com/landing/P6

This channel is searchable. When an entry appears in the search results, I want to create a link to its position in the paginated list.

So if the entry is found on the landing page (the first page of the list), the link will look something like:

<a href="{path='landing'}">{title}</a>

And if the entry is further back in the pagination:

<a href="{path='landing/P12'}">{title}</a>

From within the search results, what is the least expensive way to determine where the entry falls within the pagination? All of my ideas would likely require a lot of unwanted additional queries.

1
  • how do you "identify" or "pass" the entry you want to link to (or want to highlight)? With an url_title or entry_id in a url segment? – GDmac Jan 16 '13 at 16:00
3

This seems exceedingly difficult to do because, it requires not only knowing how many entries from the top the channel entry in question is, it also needs to know how many entries per page the template is set to display. If you are willing to hard code in the number of entries per page (which is not a great idea because you then break your search results the moment you change the entries template and forget to update the search results page. I guess you could do this with a plugin which you may have to use in an embedded template, and it seems to me like it would be pretty inefficient. The basic idea would be that for each search result returned you take that entry id and go do the most stripped down possible version of the query that will be done in the actual entry listing template. you are just trying to get the {count} variable back, and turn that into $page = $count$ % $the_number_of_entries_per_page. You would then need to transform that into a link to landing/P$page*$the_number_of_entries_per_page

The really inefficient thing about this is that you are performing that query for every search result, a better solution would be to create a single entry page that you can use just for the case when you've done a search and are returning a specific entry, even if you don't use that page in your normal sites' navigation.

1
  • This is more or less what I expected to hear. I'm accepting this answer, thanks Bob. – Dylan T Jan 16 '13 at 15:58
1

I'd make a new template for this. You'll need it if you have an RSS feed as well. It can be a single-entry page that's only used for search results/RSS or a monthly archive page where you can construct a link like

{path='section/archive'}/{entry_date format="%Y/%m"}/#section-{entry_id}

If there is ever a time when someone wants to link directly to a post from outside of the CMS, the paginated solution is going to fail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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