Skip to content

Instantly share code, notes, and snippets.

@unruthless
Created May 22, 2010 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unruthless/410103 to your computer and use it in GitHub Desktop.
Save unruthless/410103 to your computer and use it in GitHub Desktop.
EE template: combined index and detail page
...
{!-- Segment_2 isn't blank, so show a blog post's detail page --}
{if segment_2 != ""}
<h1>Single Post</h1>
{exp:channel:entries channel="blog" url_title="{segment_2}"}
{!-- If segment_2 isn't a URL title for any existing blog post, redirect to the landing page --}
{if no_results}
{redirect="blog/index"}
{/if}
{!-- Otherwise display the blog post, with whatever markup you want --}
<article class="blog_post">
<h1>{title}</h1>
{your_custom_blog_post_field_1}
{your_custom_blog_post_field_2}
{your_custom_blog_post_field_etc..}
</article>
{/exp:channel:entries}
{!-- Segment_2 is blank, so show the blog landing page --}
{if:else}
<h1>All Posts</h1>
{exp:channel:entries channel="blog" orderby="title" sort="asc"}
<article class="blog_post">
<h2><a href="{url_title_path='blog'}">{title}</a></h2>
</article>
{/exp:channel:entries}
{/if}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment