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.

EE2: Using segment variable to call category before entry_id_path

February 27, 2010 8:52am

Subscribe [4]
  • #1 / Feb 27, 2010 8:52am

    erfi75

    34 posts

    Hello,

    [Apologies, originally posted in how-to.]

    I recently upgraded to 2.0 and am trying to reconstruct some semblance of my old galleries via channels. I figured out how to get the categories to display using the following:

    {exp:channel:categories channel="gallery1" style="linear"}
    
    <a href="http://{path=pikchaz/testingchannel}">{category_image}</a>
    
    <strong><a href="http://{path=pikchaz/testingchannel}">{category_name}</a></strong>
    
    
    <span class="quiet">{if category_description}{category_description}{/if}</span>
    
    
    
    {/exp:channel:categories}

    Then, I tried to recreate a “recently added” display where each thumbnail is linked to that photo’s full-size display in the template “pikchaz/testingchannel”. Here’s what I tried:

    {exp:channel:entries  channel="gallery1"  orderby="date"  limit="5" }
    
        <a href="http://{entry_id_path=pikchaz/testingchannel}">{img_thumb}</a>
    
    {/exp:channel:entries}

    This ALMOST does what I want, but it is ignoring my categories (with the result that the testingchannel template just goes through all the images in the channel, rather than limiting itself to the category of the thumb a user clicked).

    I’ve read a lot of the support forums and documentation, and I think I need to use segment variables so that instead of getting a link like /pikchaz/testingchannel/46 I can get a link like /pikchaz/testingchannel/C6/46 (where C6 is a category and 46 is the entry id for the image).

    Does this make sense, or is there another approach to accomplishing a four-part URL with the last two parts being generic variables?

    You can see what’s happening at: http://www.ericfichtl.org/index.php/pikchaz/index/

    Thanks in advance. I’m stuck on this.

    Eric

    Moved to HowTo by Moderator

  • #2 / Feb 28, 2010 2:50pm

    Greg Salt

    3988 posts

    Hi Eric,

    If I understand you correctly you want to be able to show images (or just links to those images) related to the one shown when you have a URL like http://www.ericfichtl.org/index.php/pikchaz/testingchannel/46? If that’s right then you might use a channel:entries pair underneath your existing channel:categories pair that uses the Related Categories mode.

    Cheers

    Greg

  • #3 / Feb 28, 2010 4:51pm

    erfi75

    34 posts

    Hi Greg,

    Hmm, my attempts with related_categories_mode=“yes” just resulted in my gallery disappearing in pikchaz/testingchannel, and my recently added feed of thumbnails disappearing from pikchaz/index. At any rate, I don’t think that the intended result with that parameter is exactly what I want.

    Maybe I can explain the problem more simply.

    I created one channel at pikchaz/testingchannel which is supposed to be the “frame” for showing photos from any category. For this testing period, I just have two categories so far: Graffiti (C5) and Colombia (C6); entries 43, 44, and 45 are Graffiti, and entries 46 and 47 are Colombia. In isolation, this channel works—i.e., if I’m browsing the Graffiti category, only the 43, 44, and 45 appear.

    My trouble is arising on the pikchaz/index template. My intent there is to do two things:
    1. On the left, to show all my categories (including use of the {category_image} to call each category’s icon). That half of the page is working, too—if you click the Graffiti thumb or the hyperlinked word beside it, you get sent into pikchaz/testingchannel with only C5 images showing. Same goes for the other category.
    2. On the right, to show a feed of the last five images added. What I want to accomplish is that when a user clicks one of the thumbs, it (a) displays the full-size version of that image in the pikchaz/testingchannel “frame” AND (b) keeps the “previous/next” navigation related to the selected image’s category, so that the user can browse the other images in that category.

    The part I’m having trouble with is that the “recently added” feed on the right doesn’t draw the category into the URL when creating the link (pikchaz/testingchannel/C5/45) and instead directly links to the image (pikchaz/testingchannel/45). This results in my “previous/next” navigation disappearing, creating a dead end.

    This is what led me to think I had to use a segment variable in order to force the category code into the URLs coming out of this:

    {exp:channel:entries  channel="gallery1" orderby="date"  limit="5" }
    
        <a href="http://{entry_id_path=pikchaz/testingchannel}">{img_thumb}</a>
    
    {/exp:channel:entries}

    My thinking was that a segment variable could accomplish something like:

    {exp:channel:entries  channel="gallery1" orderby="date"  limit="5" }
    
        <a href="http://{entry_id_path=pikchaz/testingchannel/SEGMENT_VARIABLE_FOR_CATEGORY}">{img_thumb}</a>
    
    {/exp:channel:entries}

    But perhaps I am doing this all the wrong way. I’m basically trying to recapture the basic navigation of the old gallery module (with its next/previous within categories as well as the category jump navigation via dropdown menu or something similar). While I’m getting used to the channels approach and see its flexibility, this particular topic is tripping me up.

    Thanks for any help you can provide.

    Eric

  • #4 / Mar 01, 2010 3:07am

    John Henry Donovan

    12339 posts

    Eric,

    Untested but see if this works for you

    {exp:channel:entries  channel="gallery1" orderby="date"  limit="5" dynamic="no"}
    
        <a href="http://{path=pikchaz/testingchannel/}C{categories}{category_id}{/categories}/{entry_id}">{img_thumb}</a>
    
    {/exp:channel:entries}
  • #5 / Mar 09, 2010 5:32am

    erfi75

    34 posts

    Hi John,

    Thanks for the suggestion—I finally had a chance to try it.

    In your code, the links were malformed, rendering as /index.php/pikchaz/testingchannelC6/46. But it got me close!

    Based on your suggestion, I tried this (note addition of ’ and / either side of first closing }):

    {exp:channel:entries  channel="gallery1" orderby="date"  limit="5" dynamic="no"}
    
        <a href="http://{path=pikchaz/testingchannel}/C{categories}{category_id}{/categories}/{entry_id}">{img_thumb}</a>
    
    {/exp:channel:entries}

    This managed to get the links to form correctly, such as: /index.php/pikchaz/testingchannel/C6/47

    Unfortunately, however, it’s only accomplished half my desired outcome. While it does send me into the “pikchaz/testingchannel” template within the category of the image I’ve selected (either C5 or C6), the entry_id variable is not actually affecting the image displayed. In other words, whichever thumb I click on, the image in “pikchaz/testingchannel” begins on the highest (newest) image in the category, rather than the actual image selected. So, it’s essentially duplicating the other categories approach to my gallery that I described in my second post on this thread (the left-hand approach).

    The only way I see to link directly to an image is by leaving the category variable out of the URLs, i.e. /index.php/pikchaz/testingchannel/46. If I use index.php/pikchaz/testingchannel/C6/46 it automatically displays /index.php/pikchaz/testingchannel/47 (the latest image in C6). It is retaining my navigation links, at least, so it’s not a dead end. Perhaps there’s a clash or a disconnect between building this sort of path and the use of the {paginate} tag in the “pikchaz/testingchannel”.

    I’m eagerly awaiting that conversion script for the old galleries, as I can’t find any way to make categories, entry ids, and a channel to sync the same way that module had them working.

    Thanks for your help.

    Eric

  • #6 / Mar 09, 2010 11:52am

    Sue Crocker

    26054 posts

    Eric, this really *is* a HowTo topic. Moving there, and updating your title.

  • #7 / Mar 14, 2010 6:42am

    erfi75

    34 posts

    Hi Sue,

    If you insist that this is just a how-to, I can’t really do anything about it. But I do feel there’s some unexpected behavior here which is really what I’m trying to get to the bottom of.

    The core issue here is: Why does a correctly formed link (generated by EE’s dynamic tags) combining category and an entry ID not work as intended? It doesn’t seem logical that a variable is being included in URLs yet completely ignored.

    In real terms, why would the links /index.php/pikchaz/testingchannel/C6/46 and /index.php/pikchaz/testingchannel/C6/47 render the same entry, with the entry ID (46 or 47) completely irrelevant?

    To my mind, that is either a bug, or a design decision the logic of which is not explained in the documentation. I understand we’re still in beta, so I hope this is taken as helpful and worthy of technical comment, rather than being seen as just another case of someone not “getting” it.

    Thanks as always,
    Eric

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

ExpressionEngine News!

#eecms, #events, #releases