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.

conditionally place content before and after all sticky posts

May 23, 2012 1:01pm

Subscribe [2]
  • #1 / May 23, 2012 1:01pm

    anonymous61630

    93 posts

    I’d like the posts in my channel:entries tag to appear like this:

    sticky title
    - sticky post
    - sticky post
    - sticky post
    - sticky post

    normal title
    - normal post
    - normal post
    - normal post
    - normal post
    - normal post


    How can I achieve this?

  • #2 / May 24, 2012 1:03pm

    Dan Decker

    7338 posts

    Hi Florian,

    Thanks for your question!

    You would need 2 channel entries tag pairs in the template.

    Can you give me some context about the type of entries that will be in the 2 lists? From the same channel, etc?

    Cheers,

  • #3 / May 25, 2012 4:41am

    anonymous61630

    93 posts

    This is my channel tag:

    {exp:channel:entries limit="999" channel="projects" disable="member_data|pagination|categories" start_on="{current_time format='%Y-01-01 00:00'}" stop_before="{current_time format='%Y-12-31 23:59'}" status="current"}

    It displays projects with the status “current” that are from this year.

    How would I achieve the desired output with two Channel tags?

  • #4 / May 31, 2012 12:26pm

    Dan Decker

    7338 posts

    Hi Florian,

    Again, it depends, but one way would be to use sticky entries. In the publish form you can set an entry to be sticky. Sticky entries will always rise to the top so:

    Tag one

    {exp:channel:entries limit="999"
      channel="projects"
      disable="member_data|pagination|categories"
      start_on="{current_time format='%Y-01-01 00:00'}"
      stop_before="{current_time format='%Y-12-31 23:59'}"
      status="current"
      dynamic="off"}

    Tag two

    {exp:channel:entries limit="999"
      channel="projects"
      disable="member_data|pagination|categories"
      start_on="{current_time format='%Y-01-01 00:00'}"
      stop_before="{current_time format='%Y-12-31 23:59'}"
      status="current"
      sticky="no"
      dynamic="off"}

    That would need some refinement to get exactly what you want - like adjusting the limit= or adding an offset=

    Let me know what you think!

    Cheers,

  • #5 / Jun 11, 2012 7:34am

    anonymous61630

    93 posts

    Thank you, Dan. Although: your solution would only work if there was a fixed number of sticky posts, but there isn’t.

  • #6 / Jun 13, 2012 2:46pm

    Dan Decker

    7338 posts

    Hey Florian,

    Looks like it would need to be a custom query for the first result set then, and I’m exactly sure what that would be.

    I can move this into Development and Programming if you’d like input from the Community?

    Cheers,

  • #7 / Jun 13, 2012 2:52pm

    OwanH

    87 posts

    Hey Florian, have you considered using the Stash module together with the Channel module?

  • #8 / Jun 13, 2012 7:29pm

    OwanH

    87 posts

    Hey again Florian, I decided to go ahead and put up an example of what (I think) you are attempting to achieve. Here is a link to a page that shows the output of the code I wrote:

    http://ispheretechnologies.com/eetests/

    And here is the code:

    {exp:channel:entries channel="test_channel" disable="categories|member_data|pagination" dynamic="no"}
        {if sticky == 'y'}
            {if count == 1}
                <h2>Sticky Title</h2>
    <p>            <ul><br />
                {exp:stash:set name="close_sticky_list"}</ul>{/exp:stash:set}<br />
            {/if}<br />
            <br />
            <li>{title}</li><br />
        {/if}<br />
    {/exp:channel:entries}</p>
    
    <p>{exp:query sql="SELECT title FROM exp_channel_titles WHERE channel_id='8' AND sticky='n' ORDER BY entry_date DESC"}<br />
        {if count == 1}<br />
            {exp:stash:get name="close_sticky_list"}<br />
            </p><h2>Normal Title</h2>
    <p>        <ul><br />
        {/if}<br />
        <li>{title}</li><br />
        <br />
        {if count == total_results}</ul>{/if}<br />
        <br />
        {if no_results}<br />
            {exp:stash:get name="close_sticky_list"}<br />
        {/if}<br />
    {/exp:query}

    Note that this is just a temporary link I put up on my site to show you the output of the EE2 code. I’ll remove the page once you get this thread resolved (since this is page is on a live site 😊).

    Anyhow to explain the code, I created a test channel (whose ID is ‘8’ in the database) and added 6 test entries in there, 3 sticky, 3 not sticky. First I used an {exp:channel:entries} tag to output the sticky items. Note the use of the Stash module to store and retrieve data throughout the template. Then, instead of using a second {exp:channel:entries} tag to output the non-sticky items I used the Query module instead so that I could easily just pull in non-sticky items and filter out the sticky items for my ‘Normal Posts’ list.

    I really hope this helps you out. Let me know if it does.

  • #9 / Jun 15, 2012 3:42pm

    Dan Decker

    7338 posts

    Hey OwanH!

    Thanks for the ideas and example! I love it when the Community comes through with a helping hand.

    Cheers!

  • #10 / Jun 15, 2012 3:51pm

    OwanH

    87 posts

    Thanks Dan, glad to help out where I can. The EE Community has been good to me from day one when I first dived into the EE world so I do my best to pass on as much of the knowledge I have learned along the way (and continue to learn 😊).

    @Florian, was my example of any help?

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

ExpressionEngine News!

#eecms, #events, #releases