Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter samsonwiklund

    (@samsonwiklund)

    Can I add somekind of if-statement that if the user is viewing a specific category I can get a sticky on top of it?

    I don’t want the sticky to show up as a sticky on the main-site though, only when the user is viewing a specific category.

    The sticky I want is only for post. Can I “hardcode” it through use of permalinks within some kind of if-statement which only shows when for instance “cat=222”?

    I don’t have a “category.php” page but this is my page template:

    <?php get_header(); ?>
    
    		<!-- Content -->
    		<div id="content">
    
    			<?php if (have_posts()) : ?>
    			<?php while (have_posts()) : the_post(); ?>
    			<!-- Post -->
    			<div class="post" id="post-<?php the_ID(); ?>">
    				<div class="post-title">
    					<h2><?php the_title(); ?></h2>
    				</div>
    				<div class="post-entry">
    					<?php the_content('Read <span>more...</span>'); ?>
    					<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    				</div>
    			</div>
    			<!-- /Post -->
    			<?php endwhile; ?>
    			<?php else : ?>
    			<!-- Post -->
    			<div class="post">
    				<div class="post-title">
    					<h2>Finns inte</h2>
    				</div>
    				<div class="post-entry">
    					<p>Sorry, men du letar efter något som inte finns.</p>
    				</div>
    			</div>
    			<!-- /Post -->
    			<?php endif; ?>
    
    			<div class="clear"></div>
    
    		</div>
    		<!-- /Content -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    Thread Starter samsonwiklund

    (@samsonwiklund)

    i can’t seem to edit my post but:

    The sticky I want is only for post

    should read:

    The sticky I want is only for one post.

    Just copy your index.php (or archive.php) to category-222.php then add this before the loop:

    <?php
    //get one post, post id=342
    $args=array(
      'post__in'=> array (342)
      );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><small><?php the_time('m.d.y') ?></small> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    ?>

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy
    Category Templates

    Thread Starter samsonwiklund

    (@samsonwiklund)

    Is there anyway I could hardcode the category-variable in the code so the url could be:

    http://www.url.com/whatever.php

    instead of

    http://www.url.com/whatever.php?cat=222

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Want to make a post sticky, but only when a specific cat is being viewed’ is closed to new replies.