MD Detect Page Type
Detect if you are on pagination page, category page, or yearly archive page.
Download MD Detect Page Type 1.0.1 (1kb zip)
This version posted September 29, 2008
Downloads: 43
You can use a single template to handle the “landing page” for an area as well as the single-entry version of the page with a couple
{if segment_3 != ""}
and
{if segment_3 == ""}
conditionals. But when you introduce pagination, everything gets messed up. The goal was to avoid having to make a separate template to handle the single entries when pagination is used on the the same template. The URLs should look like the following using the (very basic) code sample that follows.
www.site.com/group/template/ - The “landing” page, that may include paginated items
www.site.com/group/template/P## - A paginated page in this area
www.site.com/group/template/itemtitle/ - Using the same template for a single entry
Super Basic Example:
{exp:md_detect_page_type url_segment="{segment_3}"}
Pagination Page: {if pagination_page}This is a Paginated Page{/if}<br />
Category Page: {if category_page}This is a Category Page{/if}<br />
Yearly Archive Page: {if yearly_archive_page}This is a Yearly Archive Page{/if}
{/exp:md_detect_page_type}
Simple usage example, allowing Pagination and Single Entry on one template:
{exp:md_detect_page_type url_segment="{segment_3}"}
{!-- if segment_3 is empty or it equals P## --}
{if pagination_page || segment_3 == ""}
{!-- list all the entries with pagination --}
{exp:weblog:entries weblog="weblog" paginate="bottom" limit="999"}
<h2>{absolute_count}. {title}</h2>
<p>{custom_field}</p>
{paginate}
<div class="pagination">
<p>Page {current_page} of {total_pages} pages. {pagination_links}</p>
</div>
{/if}
{/exp:weblog:entries}
{!-- otherwise, segment_3 has something in it
and it is not pagination. Show single entry --}
{if:else}
{exp:weblog:entries weblog="weblog" limit="1"}
{if no_results}<p>Sorry! Couldnt find that entry.</p>{/if}
<h2>{title}</h2>
<p>{custom_field}</p>
{/exp:weblog:entries}
{/if}
{/exp:md_detect_page_type}
Also check out this EE forum thread that spawned the plugin: Detecting a single entry using EE code. A thread called Can’t get pagination to work deals with this pagination issue using PHP.
Here is a link to the thread for this plugin in the EE Forums: Plugin: MD Detect Page Type.
Release Notes
1.0.1 Sep 29, 2008
- Added ability to check for category page and yearly archive page types
- Changed name from md_detect_pagination to md_detect_page_type
1.0.0 Sep 28, 2008 (5 downloads)
Initial release.
This entry was last updated September 29, 2008.
Sorry, comments are closed.