SEF url for EE categorized entries

If you have categories for a weblog entries, the url for entry category page is not look so meaningful.
Let you have a weblog named “news” and categories for this weblog is international, sports, market etc.
You may want the urls like –

http://www.example.com/news/
http://www.example.com/news/sports/
http://www.example.com/news/markets/
http://www.example.com/news/international/
http://www.example.com/news/sports/lorem-ipsum

which is meaningful, clean and organized. EE doesn’t has built in feature for this. You can do this
in a various way – using php code in template, using query module. I’ve done this using EE query module
which is available only in commercial version of EE. If you have weblog, categories ready – see my sample
template below to make URL SEF


{assign_variable:my_weblog="news"}
{assign_variable:my_template_group="news"}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' lang='en-GB' xml:lang='en-GB'>

<head>

	{if segment_2=="" AND segment_3==""}
	<!-- news landing page -->
    
		{exp:weblog:entries weblog="news_index" orderby="date" sort="desc" limit="1"  rdf="off"  dynamic="on"}
		<title>{news_page_title}</title>
		<meta http-equiv="Content-Type" content="text/html; charset={charset}" />
		<meta name="description" content="{news_meta_desc}">
		<meta name="keywords" content="{news_meta_keys}">
		{/exp:weblog:entries}
	
	{if:elseif segment_2!="" AND segment_3==""}
	<!-- news category article page -->

	{exp:query sql="SELECT cat_name, cat_description FROM exp_categories WHERE cat_url_title = '{segment_2}'"}
	        <title>{site_name} - {cat_name}</title>
			<meta http-equiv="Content-Type" content="text/html; charset={charset}" />
			<meta name="description" content="{cat_description}" />
		    <meta name="keywords" content="{cat_description}" />
	{/exp:query}
	
	{if:elseif segment_3!="" AND segment_2!="previous"}
	<!-- news single article page -->

		{exp:weblog:entries weblog="{my_weblog}" orderby="date" sort="desc" dynamic="off" url_title="{segment_3}" limit="1"  rdf="off"}
		<title>{site_name} - News - {news_page_title}</title>
		<meta http-equiv="Content-Type" content="text/html; charset={charset}" />
		<meta name="description" content="{news_meta_desrc}">
		<meta name="keywords" content="{news_meta_keys}">
		{/exp:weblog:entries}			

	{if:elseif segment_3!="" AND segment_2=="previous"}
	<!-- news entries page with pagination -->

		{exp:weblog:entries weblog="news_index" orderby="date" sort="desc" limit="1"  rdf="off"  dynamic="on"}
		<title>{news_page_title}</title>
		<meta http-equiv="Content-Type" content="text/html; charset={charset}" />
		<meta name="description" content="{news_meta_desrc}">
		<meta name="keywords" content="{news_meta_keys}">
		{/exp:weblog:entries}
		
	{/if}
	
</head>
<body>

		{if segment_2=="" AND segment_3==""}					

		<!-- blog landing  page -->
				{exp:weblog:entries weblog="{my_weblog}" orderby="date" sort="desc" dynamic="on" limit="10" paginate_base="news/previous"}
					<a href="{path="news"}{categories limit="1"}{category_url_title}{/categories}/{url_title}/">{title}</a>
					<p>{entry_date format="%M %d, %Y"}</p>
					{summary}
					<a href="{path="news"}{categories limit="1"}{category_url_title}{/categories}/{url_title}/">Read the rest of this entry >></a>
					
					<p>Posted under: {categories weblog="{my_weblog}" backspace="2"}<a href="{site_url}news/{category_url_title}/" title="{category_name}">{category_name}</a>, {/categories}</p>

					{paginate}
					<p>Page {current_page} of {total_pages}  {pagination_links}</p>
					{/paginate}
					
				{/exp:weblog:entries}

		{if:elseif segment_3!="" AND segment_2=="previous"}						
		<!-- blog landing  page with pagination -->
				{exp:weblog:entries weblog="{my_weblog}" orderby="date" sort="desc" dynamic="on" limit="10" paginate_base="news/previous"}
					<a href="{path="news"}{categories limit="1"}{category_url_title}{/categories}/{url_title}/">{title}</a>
					<p>{entry_date format="%M %d, %Y"}</p>
					{summary}
					<a href="{path="news"}{categories limit="1"}{category_url_title}{/categories}/{url_title}/">Read the rest of this entry >></a>					
					<p>Posted under: {categories weblog="{my_weblog}" backspace="2"}<a href="{site_url}news/{category_url_title}/" title="{category_name}">{category_name}</a>, {/categories}</p>
					{paginate}
					<p>Page {current_page} of {total_pages}{pagination_links}</p>
					{/paginate}
					
				{/exp:weblog:entries}								
		{if:elseif segment_2!="" AND segment_3==""}
			<!-- categories entry page -->
				{exp:query sql="SELECT cat_id,cat_name FROM exp_categories WHERE cat_url_title = '{segment_2}'" paginate_base="news/previous"}
				
					{exp:weblog:entries weblog="{my_weblog}" orderby="date" sort="desc" dynamic="on" limit="100"  category="{cat_id}"}
						<a href="{path="news"}{segment_2}/{url_title}/">{title}</a>
						<p>{entry_date format="%M %d, %Y"}</p>
						{summary}
						<a href="{path="news"}{segment_2}/{url_title}/">Read the rest of this entry >></a>
						<p>Posted under: {categories weblog="{my_weblog}" backspace="2"}<a href="{site_url}news/{category_url_title}/" title="{category_name}">{category_name}</a>, {/categories}</p>

						{paginate}
						<p>Page {current_page} of {total_pages}  {pagination_links}</p>
						{/paginate}
						
					{/exp:weblog:entries}
					
				{/exp:query}
			
		{if:else}
		<!-- single entry page-->
			{exp:query sql="SELECT cat_id,cat_name FROM exp_categories WHERE cat_url_title = '{segment_2}'"}
				{exp:weblog:entries weblog="{my_weblog}" orderby="date" sort="desc"  url_title="{segment_3}" dynamic="off" rdf="off"}		
	  
						<p>

							{exp:weblog:prev_entry weblog="news" category="{cat_id}" entry_id="{entry_id}"}
							<a href="{path="news/{segment_2}"}">Previous Article</a> | 
							{/exp:weblog:prev_entry}
				  
							{exp:weblog:next_entry weblog="news" category="{cat_id}" entry_id="{entry_id}"}
							<a href="{path="news/{segment_2}"}">Next Article</a>
							{/exp:weblog:next_entry}							 
							
						</p>
						<p><a href="{path="news"}{segment_2}/{segment_3}/#more">{title}</a></p>
						{body}
						
				{/exp:weblog:entries}
			{/exp:query}														  				
				<p><a href="{path=news}{segment_2}/"> &lt;&lt; Back to list of articles</a></p>

		{/if}			
						
</body>
</html>

This is just a sample template page with my custom fields for categorized entries. You can customize is as needed. I’ve implemnted this on
http://www.ingleandrhode.co.uk/ethical-diamonds-blog/. Hope this may help you.

Advertisements

4 thoughts on “SEF url for EE categorized entries

  1. good solution.

    but in single entry, I can get prev_entry and next_entry any thing.
    does your template works well in single entry page ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s