0

I have asked this question in the official EE forum but didn't get any replies so thought about asking the same question here, hope someone can help?!

What I am trying to do:

I have the SolSpace user module installed and pulling the username of my members as segment 1 (e.g. www.domain.com/peter) now I have a channel where my users can enter a blog entry but I want each user to have their own blog address (e.g. www.domain.com/peter/blog) so got all that working fine.

The problem:

When I go to www.domain.com/peter/blog I see Peter’s entries and that’s good and all but when I click on the title to read more I get the permalinks page for that blog entry, what I would like to get is www.domain.com/peter/blog/hello-world served on the screen and no matter what I try it’s getting that the 3rd segment to show that entry…

This is my code:

{if segment_2 =="blog"}
 {exp:channel:entries channel="blog" username="{segment_1}" limit="10" dynamic="no"}
  {title}
 {/exp:channel:entries}
{if:else}
 {exp:channel:entries channel="blog" username="{segment_1}" limit="1" dynamic="yes"}
  {title}
 {/exp:channel:entries}
{/if}

Also tried

    {if segment_2 =="blog"}
     {exp:channel:entries channel="blog" username="{segment_1}" limit="10" dynamic="no"}
      {title}
     {/exp:channel:entries}
    {/if}
    {if segment_2 =="blog" AND segment_3 ==""}
     {exp:channel:entries channel="blog" username="{segment_1}" limit="1" dynamic="yes"}
      {title}
     {/exp:channel:entries}
    {/if} 

I have tried so many different combos to get the 3rd segment to show but nothing shows or I get a blank page.

I can link the page to www.domain.com/blog/hello-world and that works but I wanted to get www.domain.com/peter/blog/hello-world.

I have am running EE 2.5.5

I hope I made sense, if not please let me know and I will try again, I know the code is wrong but if someone can put me on the right track…

Thanks in advance. Tony

2
  • Just a heads up and not related to your problem but it sounds from your description that what you're doing might fall afoul of the EE Licence agreement. Specifically this restriction; "Use the Software as the basis of a hosted blogging service, or to provide hosting services to others." More here. ellislab.com/expressionengine/user-guide/about/license.html
    – foamcow
    Commented May 8, 2013 at 12:05
  • Thanks foamcow, in my case I have a channel called "blog" and everyone adds content to that channel, a bit like being an editor for the site, they in theory don't have an actual blog installed on my server. I think they mean offering EE core on shared hosting solutions a bit like WordPress "one click installs".
    – Tony
    Commented May 8, 2013 at 13:01

2 Answers 2

1

I found the issues on your code samples.

You want to use "/peter/blog/hello-world" for the unique entry page, right?

On the first one, the second possibility of your conditional just runs if the segment_2 isn't "blog", but the segment_2 will always be "blog".

On the second one, the second conditional just runs if there's no segment_3, but you need the segment_3 to find the the entry.

So lets fix it!

First of all, how are you coding the permalinks? Are you using "{url_title_path='blog/{segment_2}'}"? Personally, I prefer to use relative links, so I used them on my code samples.

And I strong suggest you to avoid advanced conditionals. From the docs:

Simple conditionals are parsed before module tags, but advanced conditionals are parsed after module tags. If a simple conditional evaluates false, ExpressionEngine simply ignores a module tag within that conditional, neither rendering it nor displaying it. But if an advanced conditional evaluates false, ExpressionEngine can only hide the output of the already fully rendered module tag. That amounts to a big difference in performance.


Your first option is:

{if segment_2 == "blog"}
    {if segment_3 == ""}
        {exp:channel:entries channel="blog" username="{segment_1}" limit="10" dynamic="no"}
          <a href="/blog/{segment_2}/{url_title}">{title}</a>
        {/exp:channel:entries}
    {/if}
    {if segment_3}
        {exp:channel:entries channel="blog" limit="1" dynamic="yes"}
            {title}
        {/exp:channel:entries}
    {/if}
{/if}

Since two entries can't use the same url_title on the same site, there's no need for the username parameter on the unique entry page.

Unfortunately, this is gonna break your pagination in case of, for example, "/peter/blog/P10".

Lets improve it.


You can use the segment_3 as a marker for your posts: "/peter/blog/posts/hello-world". In this case:

{if segment_2 == "blog"}
    {if segment_3 != "posts"}
        {exp:channel:entries channel="blog" username="{segment_1}" limit="10" dynamic="no"}
          <a href="/blog/{segment_2}/post/{url_title}">{title}</a>
        {/exp:channel:entries}
    {/if}
    {if segment_3 == "posts"}
        {if segment_4}
            {exp:channel:entries channel="blog" limit="1" dynamic="yes" url_title="{segment_4}"}
                {title}
            {/exp:channel:entries}
        {/if}
        {if segment_4 == ""}
            {redirect="404"} or what else you want to do in case of "/peter/blog/posts/".
        {/if}
    {/if}
{/if}

EECMS just looks for entry_id or entry_title on {segment_2} and {segment_3}. Because of this, we need to use the url_title parameter.

This works fine, but maybe you can't use the word "posts" on segment_3.


The solution for this is to use RegEX to check the pagination. The addon switchee allows the use of RegEx on conditional tests.

{if segment_2 == "blog"}
    {exp:switchee variable="{segment_3}" parse="inward"}
        {case value="#P\d+$#|''"}
            {exp:channel:entries channel="blog" username="{segment_1}" limit="10" dynamic="no"}
              <a href="/blog/{segment_2}/{url_title}">{title}</a>
            {/exp:channel:entries}      
        {/case}
        {case default="Yes"}
            {exp:channel:entries channel="blog" limit="1" dynamic="yes"}
                {title}
            {/exp:channel:entries}
        {/case}
    {/exp:switchee}
{/if}

The first case checks for "P" followed by more than one digit or "", while the second deals with all other cases.

I hope it helps.

Bye!

2
  • Hi Robson, THANK YOU!!!! This worked like a charm :) I was hitting my head on the wall with this issue and I really appreciate the time you took to write it all down in detail, not only did it work but I learned from your code so thanks again for your help! Really really appreciated! Awesome
    – Tony
    Commented May 13, 2013 at 9:07
  • I fixed the second sample. Please, forgive me. I wrote this answer really late at night. Bye!
    – Sobral
    Commented May 13, 2013 at 11:41
0

Depending on how you are arriving to the blog template group, you may not necessarily need the conditional around segment_2 unless there's other items that may be displayed. In any event, maybe give this a try:

{if segment_2 == "blog" AND segment_3 == ""} entries loop for user's full list of entries {if:elseif segment_2 == "blog" AND segment_3 != ""} entries loop for user's single entry {/if}

The issue I saw above is that segment_2 condition was met by both conditions. This way, it's force to a yes or no with each.

I would also recommend wrapping this with Croxton's ifelse add-on so the outer conditional is parsed earlier and therefore the insides only get parsed if the outside condition is met.

Also, you may need/want to add a parameter to your entries loop to narrow it to the specific entry, like url_title="{last_segment}" or url_title="{segment_3}"

1
  • WOW thanks for the quick reply Jean St-Amand looks good I will try that out for sure. Plug in looks good too :) Thanks again
    – Tony
    Commented May 8, 2013 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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