ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

What's the best solution to achieve the following setup...

December 06, 2012 11:42am

Subscribe [2]
  • #1 / Dec 06, 2012 11:42am

    cwgarner

    19 posts

    I am trying to achieve the following setup, using just one template, and I hope someone can help point me to the best solution. Here it goes…

    > If a user navigates to http://www.domain.com/news the ‘news’ template displays excerpts from the latest 5 channel entries, with additional entries being paginated.

    > If a user navigates to http://www.domain.com/news/article_url_title the ‘news’ template displays one full channel entry based on the url_title passed in {segment_2}.

    > If no results are returned based on {segment_2} the page redirects to a custom 404.

    —I have done all the above, it’s this next bit I can’t figure out—

    > If a user is looking at the paginated content at http://www.domain.com/news/P5 my existing code directs them to the 404 as I have no channel entries with ‘P5’ as the URL title.

    So essentially, how do I go about saying:

    If segment_2 && no results, redirect to 404, unless it's a paginated page?

    I hope this makes sense and someone is able to help.

    Many thanks in advance,

    Chris

  • #2 / Dec 06, 2012 12:05pm

    MadWebDesigns

    147 posts

    Hi Chris,

    Are you using the /news/index.html page to do both of these things? If so, there are 2 ways you can do this:

    Option1:
    - Add a PHP if statement to your /news/index.html page that will check for the P# in segment2 and not display your detailed page. To do that add something like the following PHP:

    <?php
    if("{segment_2}" != "" && preg_match("/P[0-9]/i","{segment_2}") == 0){
    ....display the detailed channel entry page stuff
    }
    else{
    ....display the latest 5 excerpt and paginate if needed
    }
    ?>

    Doing it this way might require that you embed your channel entries tags for it to work properly.

    Option2:
    1) Create a new template called “view” in the “news” template group. You will use this template to display your channel details page.
    2) Update your links to go to /news/view/article_url_title

    I hope that helps.

    Cheers,

    Mike

  • #3 / Dec 06, 2012 12:09pm

    cwgarner

    19 posts

    Thanks for your response Mike.

    Option 2 is how I’m currently going about it - but for a number of reasons I wish to avoid having the additional template ‘view’.

    Option 1 looks perfect for what I want, so I’ll give that a go and let you know how I get on.

    Many thanks again,

    Chris

  • #4 / Dec 07, 2012 10:05am

    cwgarner

    19 posts

    I have implemented your solution Mike (Option 1) and it works perfectly. Many thanks.

  • #5 / Dec 07, 2012 10:27am

    MadWebDesigns

    147 posts

    I’m glad it worked for you. All the best.

    Mike

  • #6 / Dec 07, 2012 10:57am

    cwgarner

    19 posts

    Ah - just run across an issue.

    How would you go about this if PHP is passed at OUTPUT and not INPUT. I have it working when PHP is passed at input but if set to output, so other bits of the page can work, it fails at the preg_match stage and redirects to the 404.

    Any suggestions?

    Cheers, Chris

  • #7 / Dec 07, 2012 11:02am

    MadWebDesigns

    147 posts

    Ah, you will have to put your channel entries tags in another template and embed them. This is a parse order issue.

  • #8 / Dec 07, 2012 11:04am

    cwgarner

    19 posts

    Ah Ok, will give that a go now. Thanks again for quick response. C

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases