Recent Topics

1 Jan 27, 2005 08:37    

I read in other posts about making a category or blog just for "sticky" posts. But then they go on to only explain how to do it with a blog.

Couldn't you just make a category called "sticky" and code just that category to display at the desired place in the template. (I did this kind of thing in MT all the time) If this is possible, what is the proper code to make it work?

Thanks if anyone can explain this.

2 Feb 01, 2005 03:44

using a simple variation of my snips post in the hacks area of the forum, you could easily have a sticky category, and have that displayed before all of your other posts.

thats a start to get you thinking, I can do it tommorow, if need be.

3 May 25, 2006 23:42

Okay, Whoo ... I'll bite!

I needed a sticky post (or sticky category) and found your hint of a solution to be the way I wanted to go, as I'm not keen on file hacking and a category designation seemed logical. I had a look at your "snips" deal and realized that the only real change was to keep the post FIRST (well, maybe a few others).

So, I'll post what I did, as others may find it useful, but keep in mind that in this example, my goal was to get a sticky post on top of a "Blog All", which also happens to be the main, index.php blog for the site. The sticky is ONLY on blog ALL (though could be on every one) and only floats to the top of the first page (if you go page deeper into Blog All, you'll lose the sticky).

This was done for an Amsterdam (v0.9.0.12) version of b2evolution.

Step one: Make a sticky category in Blog All (cat #89 for this example).

Step two: Add the following to _main.php for the skin (essentially an abbreviated blog loop, where the whole sticky post(s) are wrapped in a single DIV (id=stuck), each individual sticky is wrapped in a DIV (class=sticky) and contains post title, trackback auto discovery, edit link (if logged in), and comment link ... in addition to the sticky content).

			    <?php  // Start Sticky Category Posting
				if ($blog==1 && $disp!='single') 
                  { 
                  echo '<div id="stuck">';
                  $StickyList = & new ItemList( '1', array(), '', '', -1, 89 );
                  if( isset($StickyList) ) while( $Item = $StickyList->get_item() )
                    {
                    if ($Item->get('main_cat_ID')=='89') 
                      {  
                      echo '<div class="sticky storycontent">'; locale_temp_switch($Item->locale);
                      echo '<h3>'.$Item->title.'</h3>'; $Item->content();
                      echo '<div class="itemdetails">'; $Item->trackback_rdf();
                      if( is_logged_in() ) 
                        { 
                        echo '<span class="edit"><a href="', 
                        $admin_url, '/b2edit.php?action=edit&amp;post='; the_id(); 
                        echo '&amp;submit=%A0+Edit+%A0" title="Edit post">';
                        echo '<img src="img/01_item1.gif" alt="" />  &nbsp;Edit</a></span>';
                        }
                      echo '<span class="item3">'; $Item->feedback_link('comments');
                      echo '</span>';
                      echo '</div></div>'; 
                      }
                    }
                  echo '</div>';
                  }
                // End Sticky Category Posting   
                ?> 

IMPORTANT - Insert the above code just BEFORE the main blog loop, which, in most _main.php files, starts with

					if( isset($MainList) ) $MainList->display_if_empty(); // Display message if no post
					if( isset($MainList) ) while( $Item = $MainList->get_item() )
					{


Step 3: Add a bit to the main blog loop, to surpress the posting of any 'stick posts'. I put it right after the start of the main blog loop.

<?php // skip sticky
  if($blog==1 && $Item->get('main_cat_ID')=='89' && $disp!='single') { continue; }
?>

I think this will work fine in this situation. It allows unique styling for the group of sticky posts, should there be more than one, and also for the individual posts. The only immediate drawback, I can see, is that the post count on the page will be wrong, by however many number of "sticky posts" there are on that page. (e.g. - if the number of posts per page is set to 10, they'll only be 9 posts on whatever pages contain 1 sticky post). Not something I think people would even notice, unless someone posted a whole bunch of sticky posts, one after the other.

Sample of the finished dealie (till it's modded or deleted, anyway) ... [url=http://roadsassy.com/spicedsass]here[/url]. "Look ma, no hacks!" :D

Thanks for the start, whoo! And any comments or suggestions about how to make this more efficient, would be appreciated.

(I'm genearally of the "Hey, it works, I'm done." mentality and not completely adroit at knowing what hoops the machine has to jump through to get done what I've requested of it.) :(

4 May 26, 2006 00:37

@whoo
I realy like "snips" as it seems an ideal way to implement "MiniPosts" like [URL=http://www.webjillion.com/]Adam Howell @ WebJillion[/URL]. without "comments" and all that other fluff.

@ Scott.. nice work. BTW that site's Blogroll list is a candidate for the worlds longest :)


Form is loading...