Sticky post for each category

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
johnny-hunter
Regular
Posts: 7
Joined: Mon Jun 24, 2013 4:49 pm

Sticky post for each category

Post by johnny-hunter »

Hi there: my site is a IT tutorial site, and I divide it into multiple categories. Under "home" I have a "read me" post and make it "sticky" to give a intro. I also intend to create one or more sticky posts per category, but when I did, it replaced the "read me" under "home" menu.

Is it doable? To create sticky posts per categories, and they will appear on the top of the page for that particular category, nowhere else.

Thanks,
John
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Sticky post for each category

Post by garvinhicking »

Hi!

It shouldn't have replaced your "home" sticky post, but actually be added to the list of it. Sticky postings are always uniquely sticky, we currently have no "sticky only in category" attribute. This is also rather complex and not too easy to add, so I'm afraid there is no easy way I can offer that to you.

You can exclude certain categories for the frontpage of your blog, however that would mean no posts would ever show up on the home page for these categories, so that might be even worse than your current idea.

What you also could do is to edit your entries.tpl template and there, you could hard-code a smarty query to never show specific postings (by their ID) on the "start" view.

Depending on your template, the entries.tpl would then look like this:

Code: Select all

...
 {foreach from=$entries item="dategroup"}
    <div class="serendipity_Entry_Date">
        {if $dategroup.is_sticky}
        <h3 class="serendipity_date">{$CONST.STICKY_POSTINGS}</h3>
        {else}
        <h3 class="serendipity_date">{$dategroup.date|@formatTime:DATE_FORMAT_ENTRY}</h3>
        {/if}

        {foreach from=$dategroup.entries item="entry"}
        
        {if !$dategroup.is_sticky OR NOT $startpage OR ($startpage AND $entry.id != 47 AND $entry.id != 48)}
            {assign var="entry" value=$entry scope="parent"}
            <h4 class="serendipity_title"><a href="{$entry.link}">{$entry.title}</a></h4>
             ...
         {/if}
         {/foreach}

What is new is this line:

Code: Select all

        {if !$dategroup.is_sticky OR NOT $startpage OR ($startpage AND $entry.id != 47 AND $entry.id != 48)}
just at the beginning of the inner foreach loop per each entry (and the closing {/if} just before the closing related {/foreach}). This makes sure that an entry is only printed if it's either not a sticky entry, or the startpage is currently not being shown, or if it's the startpage but NOT ID #47 or #48 of an entry.

#47 and #48 would be an example of IDs for sticky category postings that you don't want on your startpage....

(You could actually build an event plugin to filter out those IDs already in the SQL fetching routine rather then "hiding" them on the blog, but that would be much more work. Also, you could even use jquery/CSS to hide specific category entries if you are more efficient with that...)

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Sticky post for each category

Post by Don Chambers »

Actually, in your case, this should work because you are using the Kinetic template.

The first box on your start page is not actually assigned to any particular category, so it is fetching either the latest entry, or the most recent sticky entry. Using the template's configuration options, assign this first "full width box content" to the category "Home". If you have a "read me" post marked as sticky, it will be the first entry shown in this box. It will be the only entry shown if you have that box configured to only show one entry for the category "Home", or if you only have a single entry for the category "home" (which is presently true).

The next two boxes on your start page are "Design Patterns" and "Frameworks". If you mark an entry within either of these categories as sticky, and the entry is NOT also assigned to the category "home", it should not show up in the first box on your home page, provided that first box is assigned to the category "home". These sticky entries will always be the first entries shown in a category view. They also have a background color different from regular entries, which you can change via css if you wish.

Right now, the reason your second sticky entry replaced the first is solely because that first box is not currently assigned to any category, so it defaults to showing the most recent entry, or the first sticky entry.
=Don=
Post Reply