Support » Themes and Templates » Enable Sticky Post

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:

    /* 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 class="cb"></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)
  • esmi


    Forum Moderator

    Where did you download this theme from?

    It’s the “Newspapertimes” theme by Magazine3 (http://magazine3.com/newspapertimes/)



    Forum Moderator

    I’m sorry but as you are using a commercial theme, you need to seek support from the theme’s vendors.

    They told me that they can’t give support for coding inside their themes…

    Please can you at least tell me what is the function to display sticky posts only if there are any? Something like “if there is sticky get sticky, if not get post/loop”…



    Forum Moderator

    There is no “theme function” for displaying sticky posts. Sticky posts are automatically returned at the top of the standard query on the main post page by WordPress core. Also we do not support commercial themes here as you paid for support when you bought the theme. It is not our place to keep theme vendors in business.

    thank you anyway!

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