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.

Display channel entries on certain pages only?

December 07, 2010 12:25am

Subscribe [4]
  • #1 / Dec 07, 2010 12:25am

    Zygar

    3 posts

    Hi there, I just started using ExpressionEngine yesterday and for the most part have found it an absolute pleasure to use! However, I’ve run into a bit of a roadblock with a client site that I’m using this on.

    Part of the brief is to have side buttons that can be told to appear on some pages but not others. The user should be able to go into the admin page, add a button, and tell it to appear on say, Home, Location and News.

    My initial plan was to have a textinput field (called pages) where the user can simply type in the pages that they want it to appear on, separated by |s. This is the code I have in my template so far:

    {exp:channel:entries channel="sidebutton" dynamic="no"}
        {if segment_1 == '{pages}'}
        <a href="http://{link}" class="side-button"><h4>{title}</h4><p>{subtitle}</a><br />
        {if:else} <br />
        {/if}<br />
    {/exp:channel:entries}

    This works with a single page (the button that’s showing here has the field “pages” set to “location”), but as soon as you add any more pages to the field it stops working. This isn’t surprising, as I assume EE is parsing the field literally: as “location|vision” which obviously doesn’t match any URLs on the site.

    I’m a bit stumped on this one. Is there a way to get EE to parse | as, say, bash would? (as an OR)

    Or am I going about this completely the wrong way?

    Thanks very much in advance!

  • #2 / Dec 07, 2010 10:12am

    Sue Crocker

    26054 posts

    Welcome to the ExpressionEngine forums, Zygar.

    Since you’re new to the EE forums, have you seen EEWiki:// How to Post a Support Request?

    Have you considered using a check box field to store these?

  • #3 / Dec 07, 2010 12:57pm

    Paul Stone

    97 posts

    Hi Zygar,

    So does a page only ever have one side button, or does it need to have one or more?

    Thanks,
    Paul.

  • #4 / Dec 07, 2010 4:19pm

    Zygar

    3 posts

    @Sue:
    Thanks for the link—it looks like I posted this in the wrong place, sorry! Could you move it to the Codeshare corner please?
    A checkbox field could work, I might have to look into that. Is there any way to make a checkbox field automatically pull a list of all the top level pages? (/news/, /location/, etc.) My inclination would be to somehow base this on the navigation menu so that when the client adds a page, they don’t have to change any field settings.

    @Paul: A page probably won’t ever have more than 4 buttons. I assume this should be simple enough with a limit=4!
    At this point though, I’m just figuring out the best way of getting the loop that pulls the side buttons in to check the current page against the list of pages that the button should be displayed on.

  • #5 / Dec 08, 2010 12:05am

    Zygar

    3 posts

    I got it working for the regular buttons, but now I’m tearing my hair out trying to get it work for advertisements.
    For some reason, EE is ignoring anything I stick inside the if statement. If I try to embed a template, nothing happens, if I try to embed imgsizer, it shows as plaintext, if I try to nest another if or channel tag, everything blows up rather spectacularly. 

    This is the code I’m using for buttons, which works perfectly:

    {exp:channel:entries channel="sidebutton" dynamic="no"}
        {pages}    
            {if segment_1 == '{item}' }    
                <a href="http://{link}" class="side-button">_            <h4>{title}</h4><p>{subtitle}_            </a><br />
            {if:else}<br />
            {/if}<br />
        {/pages}<br />
    {/exp:channel:entries}

    This is the code that I’m using for advertisements, which doesn’t work.

    
    
    

    How can I work around this?

  • #6 / Dec 08, 2010 5:39pm

    Ingmar

    29245 posts

    Could you move it to the Codeshare corner please?

    So moved.

  • #7 / Dec 09, 2010 1:26pm

    Boyink!

    5011 posts

    I’d suggest looking into the Playa add-on.  Create a channel of button options, then use a Playa field in the main channel where your users can select and order which buttons need to appear.

  • #8 / Dec 20, 2010 8:43pm

    Zygar

    3 posts

    Thanks for your reply!

    I eventually managed to get it working by simplifying the functionality—I simply made advertisements their own channel. Playa looks handy though, and I’ve kept it bookmarked in case I need it in the future.

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

ExpressionEngine News!

#eecms, #events, #releases