EllisLab text mark
Advanced Search
     
conditionally place content before and after all sticky posts
Posted: 23 May 2012 01:01 PM   [ Ignore ]
Avatar
Joined: 2008-03-07
126 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?

 
Posted: 24 May 2012 01:03 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2005-10-18
7340 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,

 Signature 

How may I help you?

 
Posted: 25 May 2012 04:41 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2008-03-07
126 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?

 
Posted: 31 May 2012 12:26 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2005-10-18
7340 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,

 Signature 

How may I help you?

 
Posted: 11 June 2012 07:34 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2008-03-07
126 posts

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

 
Posted: 13 June 2012 02:46 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2005-10-18
7340 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,

 Signature 

How may I help you?

 
Posted: 13 June 2012 02:52 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-06
87 posts

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

 Signature 

——————————————————————————————————————————————
Owan Hunte - Owner & Lead Web Architect
iSphere Technologies - Barbados-based Web Development, Hosting, SEO and E-Commerce
.(JavaScript must be enabled to view this email address)
http://ispheretechnologies.com/
——————————————————————————————————————————————

 
Posted: 13 June 2012 07:29 PM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-06
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>
            <
ul>
            
{exp:stash:set name="close_sticky_list"}</ul>{/exp:stash:set}
        {
/if}
        
        
<li>{title}</li>
    
{/if}
{
/exp:channel:entries}

{exp
:query sql="SELECT title FROM exp_channel_titles WHERE channel_id='8' AND sticky='n' ORDER BY entry_date DESC"}
    {if count 
== 1}
        {exp
:stash:get name="close_sticky_list"}
        
<h2>Normal Title</h2>
        <
ul>
    
{/if}
    
<li>{title}</li>
    
    
{if count == total_results}</ul>{/if}
    
    {if no_results}
        {exp
:stash:get name="close_sticky_list"}
    {
/if}
{
/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 smile).

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.

 Signature 

——————————————————————————————————————————————
Owan Hunte - Owner & Lead Web Architect
iSphere Technologies - Barbados-based Web Development, Hosting, SEO and E-Commerce
.(JavaScript must be enabled to view this email address)
http://ispheretechnologies.com/
——————————————————————————————————————————————

 
Posted: 15 June 2012 03:42 PM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2005-10-18
7340 posts

Hey OwanH!

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

Cheers!

 Signature 

How may I help you?

 
Posted: 15 June 2012 03:51 PM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-06
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 smile).

@Florian, was my example of any help?

 Signature 

——————————————————————————————————————————————
Owan Hunte - Owner & Lead Web Architect
iSphere Technologies - Barbados-based Web Development, Hosting, SEO and E-Commerce
.(JavaScript must be enabled to view this email address)
http://ispheretechnologies.com/
——————————————————————————————————————————————