Support » Themes and Templates » Enable Sticky Post

  • Hello to all of you! I need some help…

    My theme does not support sticky posts and I need to visualize 1 sticky post on the top of my homepage that have a magazine layout. I tried to insert this code before the loop:

    <?php
    /* Get all sticky posts */
    $sticky = get_option( 'sticky_posts' );
    $args = array(
    	'posts_per_page' => 1,
    	'post__in'  => get_option( 'sticky_posts' ),
    	'ignore_sticky_posts' => 1
    );
    query_posts( $args );
    
    /* Sort the stickies with the newest ones at the top */
    rsort( $sticky );
    
    /* Get the 5 newest stickies (change 5 for a different number) */
    $sticky = array_slice( $sticky, 0, 1 );
    
    /* Query sticky posts */
    query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );
    ?>

    It works fine if I have selected at last 1 sticky post, but if I have not, my layout become a mess… How can I fix it the best way?
    This is the code of the part of my index I want change:

    <div id="featwrapper">
    <div id="feat">
    <div id="featbig">
    		<div class="featbig">
    <?php query_posts('showposts=1&cat='.get_option('mainnewscat').'&offset=0'); if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
                	<h2 style="min-height:58px;"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                  <?php if(get_option('thumbok')!="no"):?>  <?php if( has_post_thumbnail() ) { ?>
                <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('featbigimg'); ?></a>
                 <?php } else { ?>
               <a href="<?php the_permalink(); ?>">  <img src="<?php bloginfo('template_directory'); ?>/images/noimg.png" style="width:418px; height:215px;" /> </a><?php } ?>
               <?php endif?> 
    
               <?php if(get_option('thumbok')!="yes"):?>
    <?php 	$m_scrp = get_template_directory_uri() . '/includes/timthumb.php?';
                        	$m_image = '';
                        	$customfields = get_post_custom();  if (empty($customfields['image'][0])) {
    $m_image = m_theme_capture_first_image(); } else { $m_image = $customfields['image'][0]; } if (empty($m_image)) { $imgpath = $m_image_def;  	} else {
    $imgpath = $m_scrp . 'src=' . $m_image . '&w=' . 418 . '&h=' . 215 . '&zc=1'; } ?>
      <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
      <img src="<?php echo $imgpath; ?>" alt="" /> </a>
     <?php endif?>
    	    <?php the_content_limit('200'); ?>
            <div id="featbig-author"><?php _e("by", "nt"); ?> <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>" title="<?php printf( esc_attr__( 'View all posts by %s'), get_the_author() ); ?>"><?php the_author(); ?></a> | <?php _e("Published", "nt"); ?> <?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' '; ?><?php _e("ago", "nt"); ?></div>
    		 <?php endwhile; ?>	<?php else : ?> 	<?php endif; ?>
           <div id="featsmall">
           <?php query_posts('showposts=2&cat='.get_option('mainnewscat').'&offset=4'); if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
                	<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    		 <?php endwhile; ?>	<?php else : ?> 	<?php endif; ?>
           </div>
           <div class="cb"></div>
    		</div>
    		 </div>

    I’d want optional sticky posts only for “featbig” class.

    Can anybody help me? Thank you very much!

Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Enable Sticky Post’ is closed to new replies.