Advertisement
vtxyzzy

OneCategory.php

Oct 17th, 2011
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.28 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: OneCategory
  4.  
  5.   **  Create a Page and assign this template.  Create a Custom Field
  6.   **  named 'category-to-show' and assign it the name of the category.
  7.   **
  8.   **  Any sticky posts in the category will be shown before others.
  9.   **
  10. */
  11. ?>
  12. <?php global $more; $more = 0;?>
  13. <?php get_header(); ?>
  14.  
  15. <div id="content"><!-- file:OneCategory.php -->
  16. <div class="post";?><h2><?php the_title(); ?></h2></div>
  17.    <?php $this_cat=get_post_meta($post->ID,'category-to-show',TRUE);
  18.         if ($this_cat != "") {
  19.          $paged = get_query_var('paged');
  20.             $stickies = get_option('sticky_posts');
  21.             $args = array( 'category_name' => $this_cat, 'paged' => $paged,);
  22.             if (!$paged) {  // Only show stickies on first page
  23.                 $myquery_hold = $wp_query;
  24.                 $args['post__in'] = $stickies;
  25.                 query_posts($args);
  26.             $found_posts = 0;  // Use this to not show warning if only stickies
  27.             if (have_posts()) {++$found_posts; bmc_show_category($nav=false);};
  28.             unset($args['post__in']);
  29.             $wp_query = $myquery_hold;
  30.          }
  31.          $args['post__not_in'] = $stickies;
  32.          query_posts($args);
  33.          if (have_posts()) {
  34.             bmc_show_category($nav=true);
  35.          } elseif (!$found_posts) {
  36.             echo "<h4></h4>There are no posts in this category $this_cat<h4></h4>";
  37.          }
  38.       } else {
  39.          echo "<h4></h4>This page is missing the Custom Field 'category-to-show'".
  40.          "whose value is the name of the category to be shown." .
  41.          "<br />Please have the page corrected.";
  42.       } ?>
  43. </div><!-- content -->
  44.  
  45. <?php get_footer(); ?>
  46. <?php function bmc_show_category ($nav = true) {
  47.    global $mam_global_post_link_args;
  48.    while (have_posts()) : the_post(); ?>
  49.       <div class="post" id="post-<?php the_ID(); ?>">
  50.       <hr /><h2><a href="<?php echo htmlentities(add_query_arg('stayincat',get_query_var('cat'),get_permalink())) ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
  51.       <?php if (!is_sticky() && (is_category('ForSale') || is_category('WantToBuy'))) {
  52.          echo '<p>Ad placed on ';the_time('F jS, Y');echo '</p>';
  53.       } ?>
  54.       <div class="entry">
  55.         <?php $mam_global_post_link_args =
  56.                             array('stayincat' => get_query_var('cat'));
  57.           ?>
  58.          <?php the_content(' (more...)'); ?>
  59.       </div>
  60.       <?php if ($nav) { ?>
  61.          <p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />');
  62.          ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>
  63.          <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?>
  64.          </p>
  65.       <?php } ?>
  66.       <?php  echo "<a class=\"pageprevlink\" href=\"";
  67.          the_permalink();
  68.          echo "\"> Comment or Reply </a>";
  69.       ?>
  70.       <?php $mam_global_post_link_args = ''; ?>
  71.       </div>
  72.    <?php endwhile; ?>
  73.    <?php if ($nav) { ?>
  74.       <div class="navigation">
  75.       <div class="alignleft"><?php next_posts_link('&laquo; Older Entries &laquo;') ?></div>
  76.       <div class="alignright"><?php previous_posts_link('&raquo; Newer Entries &raquo;') ?></div>
  77.       </div>
  78.    <?php } // End of if $nav ?>
  79. <?php } // End of Function bmc_show_category ?>
  80.  
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement