2

I am developing a site where I need to manage the URLs like:

http://www.site.com/CATEGORY-URL-TITLE : To show the the entries of that category in segment 1

http://www.site.com/CATEGORY-URL-TITLE/ENTRY-URL-TITLE : To show the individual entry of category in segment 1.

http://www.site.com/MEMBER-USERNAME : To show all the entries of authored by member in segment 1.

http://www.site.com/MEMBER-USERNAME/ENTRY-URL-TITLE : Individual entry of that member.

Could you please anyone give me some guideline how can I manage the URL structure like that. Please let me know if there is any third party addon which can do it.

Updated:

Actually, I wouldn't like to make any changes into home template for having so many conditions for checking categories or username. So looking for some technique if another template (not home template) can be rendered for such type of URLs. I think, it would be possible with sessions_start hook but still couldn't find how to route or render a template for such type of URLs.

For example, for URI like /member_username/xyz would route/render the template template_group/template_name. As with the hook sessions_start, I would be able to check if first segment is any member's username.

I hope, it would give some more idea to share your solutions.

Thanks,

2

To answer the first two questions, you'll want to use something like Seg2Cat to get the category id.

So, for http://example.com/planet/earth/, something like this will work:

{exp:channel:entries channel="content" category="{segment_1_category_id}" url_title="{segment_2}"}
   {title}
{/exp:channel:entries}

You might want to wrap it in an {if segment_3 == ""}{/if} conditional, that way it will only run when you want to show an individual entry.

You can find more about {exp:channel:entries} and categories and pulling content by author in the EE documentation.

| improve this answer | |
  • Yes, I tried Low Seg2Cat but having issue if URL having pagination identifies like P10, P20 etc. – Bhashkar Yadav Nov 22 '13 at 9:03
  • 1
    You can use switchee to handle this pagination issues. – Robson Sobral Nov 22 '13 at 10:54
  • @RobsonSobral, could you please see my updated question. I think, it would give me more idea about what I would like to have. Please share your solution for it. – Bhashkar Yadav Nov 25 '13 at 12:28
1

First, let me say that I don't think it's a good idea to use the segment_1 to both username and category_url_title. What if both matches? If you want to keep the URL short, you can use a single character segment, like c or m for one of the cases.

I would show you how to do this using switchee and the homepage template, but you said, in your update, that you don't want to use this template.

So, my suggestion, is to map this conditions to the Template Routes add-on, by Rob Sanchez. Unfortunately, username isn't one of its wildcards.

| improve this answer | |
0

Bear with me, I formulated this for a recent install, it might be overkill.

First up, grab a pipe delimited stash of all your categories

{exp:stash:set name="master_cat_list" parse_tags="yes"}
{exp:gwcode_categories backspace="1"}{cat_url_title}|{/exp:gwcode_categories}
{/exp:stash:get_list}

In you template, test the segments

 {exp:stash:parse parse_vars="yes"}
 {exp:switchee variable="{segment_2}" parse="inward"}
  {case value=""}
  // Nothing in segment 2
  // SO... test against stashed master list, to ensure valid cat_url
  {switchee variable="{segment_1}"}
    {case value="{stash:master_cat_list}"}
      {snippet:load:exp:channel:data}
    {/case}
    {case default="yes"}
      {redirect="404"}
    {/case}
  {/switchee}
  {/case}

  {case default="yes"}
  // Something in segment 2, spit out default
  {exp:channel:entries...}
  ...
  // Use {if no_results} to ensure segment_2 is valid entry
  {/exp:channel:entries}
  {/case}
  {case value=""}
  {/case}
{/exp:switchee}
{/exp:stash:parse}

That's it in a nutshell. It's not code perfect but may be of assistance.

| improve this answer | |
  • Thanks for your input. I just updated my question. Could you please see the updated question and suggest me any solution. – Bhashkar Yadav Nov 25 '13 at 12:25
0

Not easy but Switchee to the resque (and low seg2cat):
Basic idea:

{exp:switchee variable="{segment_1}/{segment_2}" parse="inward"}
  {case value="/|#P(\d+)/$#"}
    // index: empty or paginated list
  {/case}
  {case default="yes"}
    // other
  {/case}
{/exp:switchee}

See this older thread:
http://devot-ee.com/add-ons/support/switchee/viewthread/2919

| improve this answer | |
-1

I see you want specific URLs but here's something close.

for the first add http://www.site.com/CATEGORY-URL-TITLE/cat_archive/

for the third add http://www.site.com/CATEGORY-URL-TITLE/author_archive/

{if segment_2 == "cat_archive"}
{exp:channel:entries channel="..." category="{segment_1}"}

category results ...

{/exp:channel:entries}
{if:elseif segment_2 == "author_archive"}
{exp:channel:entries channel="..." author_id="{segment_1}"}

author results ...

{/exp:channel:entries}
{if:else}
{exp:channel:entries channel="..." url_title="{segment_2}"}

specific entry ...

{/exp:channel:entries}
{/if}

Other than that you might have to use some embeds and no_results tags.

EDIT:

Then you could do something like this where the embeds get your the results you want. It you have an author with the same id as a category name, the author template would come up:

{if segment_2}
  {exp:channel:entries channel="..." url_title="{segment_2}"}
    code for single article.
  {/exp:channel:entries} 

{if:else} 
  {exp:channel:entries channel="..." author_id="{segment_1}" limit="1"}    
    {embed="group/author_results" author="{segment_1}"}

    {if no_results}
      {embed="group/category_results" cat="{segment_1}" limit="1"}
    {/if}
  {/exp:channel:entries}
{/if}
| improve this answer | |
  • @Johann... Thanks for your input... sorry but everything will be dynamic. There wouldn't be any static segment in URL except site url. – Bhashkar Yadav Nov 22 '13 at 17:28

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.