Forums

Want to make a post sticky, but only when a specific cat is being viewed (5 posts)

  1. samsonwiklund
    Member
    Posted 2 years ago #

    Is this possible at all?

  2. samsonwiklund
    Member
    Posted 2 years ago #

    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(); ?>
  3. samsonwiklund
    Member
    Posted 2 years ago #

    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.

  4. MichaelH
    Volunteer
    Posted 2 years ago #

    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

  5. samsonwiklund
    Member
    Posted 2 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags