Need Help with Post Category Filtering

  • Unknown's avatar

    Hi,

    I’ve tried many methods found online for excluding posts and displaying only those from a certain category ID, of those include:

    1. <?php $post = $wp_query->post; if ( in_category(’20’) ) { include(TEMPLATEPATH . ‘/archive-portfolio.php’); } ?>
    2.<?php query_posts(‘cat=207’); while ( have_posts() ) : the_post(); ?>
    3. ‘category’ => 207;, and ‘cat’=> ‘207’,
    4. <?php query_posts(‘cat=206); ?>

    My theme uses a custom post type with the featured image thumbnails displaying in a file called archive-portfolio.php

    Here’s the code:

    <?php /*
    Template Name: Portfolio
    */
    
    ?>
    
    <?php get_header(); ?>
    
      <div class="sixteen columns"> <h2 class="blog-heading"><?php echo of_get_option('portfhtxt'); ?></h2> <div class="blog-heading-desc"><?php echo of_get_option('portfsdcs'); ?></div></div>
    
    		 <div class="sixteen columns">
    
      <div class="portfolio-all-mainmv2">
    
     <?php $args=array( 
    
     'post_type' =>     'portfolio',
     'post_status' =>   'publish',
     'posts_per_page'    => 45,
     'caller_get_posts'  =>1,
     'paged' => $paged );
     query_posts($args);
    
     while ( have_posts() ) : the_post(); ?>
    
       <div class="portfolio-itemv2">
         <div class="pfolio-item-fixer">
     	<div class="port-thumb">
    
    <a href="<?php the_permalink() ?>"> <?php the_post_thumbnail('category-thumb'); ?></a>	
    
    </div></div>
    
    		</div>
    
            <?php endwhile; ?>
    				</div>
     <div class="clear"></div>
    <div class="pagi-main-prt">
    				<?php mtpagi_pagination($additional_loop->max_num_pages); ?>
    			</div><div class="clear"></div>
    
    <?php wp_reset_query () ?>
    
    		  </div>
    
    <?php get_footer(); ?>

    And Here’s the Function.php File:

    <?php
    
    /*
     * Loads the Options Panel
     *
     * If you're loading from a child theme use stylesheet_directory
     * instead of template_directory
     */
    
    if ( !function_exists( 'optionsframework_init' ) ) {
    	define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/inc/' );
    	require_once dirname( __FILE__ ) . '/inc/options-framework.php';
    }
    
    if ( !function_exists( 'ol_init' ) ) {
    	define( 'olp', get_template_directory_uri() . '/inc/widgets/hey-its-a-flickr-widget/' );
    	require_once dirname( __FILE__ ) . '/inc/widgets/hey-its-a-flickr-widget/heyitsflickr.php';
    }
    
    if ( !function_exists( 'pchr_init' ) ) {
    	define( 'reoc', get_template_directory_uri() . '/inc/widgets/flexible-posts-widget/' );
    	require_once dirname( __FILE__ ) . '/inc/widgets/flexible-posts-widget/flexible-posts-widget.php';
    }
    
    if ( !function_exists( 'ctmportfolio_init' ) ) {
    	define( 'porfoloitcmt', get_template_directory_uri() . '/inc/plugin/portfolio-post-type/' );
    	require_once dirname( __FILE__ ) . '/inc/plugin/portfolio-post-type/portfolio-post-type.php';
    }
    
    define('MTMS_INCLUDE', get_template_directory() . '/inc');
    define('MTMS_PLUGIN', get_template_directory() . '/inc/plugin');
    define('MTMS_PLUGIN_URL', get_template_directory_uri() . '/inc/plugin'); 
    
    require_once(MTMS_INCLUDE . '/sm-kodes.php');
    require_once(MTMS_PLUGIN . '/shortcodes/shortcodes-ultimate.php');
    
    require_once(MTMS_PLUGIN . '/per-page-sidebars.php');
    
    /*
     * Make theme available for translation
     * Translations can be filed in the /languages/ directory
     */
    load_theme_textdomain( 'mi', get_template_directory() . '/languages' );
    
    add_theme_support( 'automatic-feed-links' );
    
    if ( ! isset( $content_width ) ) $content_width = 960;
    
    if ( function_exists('register_sidebar') )
    register_sidebar(array(
    'name' => 'Sidebar-Widgets',
    'before_widget' => '<div class="side-cats2"><div class="sider-22">',
    'after_widget' => '</div></div>',
    'before_title' => '<h2>',
    'after_title' => '</h2>',
    ));
    
    if ( function_exists('register_sidebar') )
        register_sidebar(array(
    	    'name' => 'Footer First Widget',
    		'id' => 'footer-first-widget',
            'before_widget' => '<div class="footer-first-widget">',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="footer-widget-title">',
            'after_title' => '</h2>',
        ));
    
    if ( function_exists('register_sidebar') )
        register_sidebar(array(
    	    'name' => 'Footer Second Widget',
    		'id' => 'footer-second-widget',
            'before_widget' => '<div class="footer-second-widget">',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="footer-widget-title">',
            'after_title' => '</h2>',
        ));	
    
    if ( function_exists('register_sidebar') )
        register_sidebar(array(
    	    'name' => 'Footer Third Widget',
    		'id' => 'footer-third-widget',
            'before_widget' => '<div class="footer-third-widget">',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="footer-widget-title">',
            'after_title' => '</h2>',
        ));		
    
    if ( function_exists('register_sidebar') )
        register_sidebar(array(
    	    'name' => 'Footer Fourth Widget',
    		'id' => 'footer-fourth-widget',
            'before_widget' => '<div class="footer-fourth-widget">',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="footer-widget-title">',
            'after_title' => '</h2>',
        ));		
    
    	register_nav_menus( array(
            'primary' => __( 'Primary Navigation'),
    
        ) );
    // remove menu container div
    function my_wp_nav_menu_args( $args = '' )
    {
        $args['container'] = false;
        return $args;
    } // function
    add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
    
    /********************** Posts Thubmnail *******************************/
    
    add_theme_support( 'post-thumbnails' );
    add_image_size( 'category-thumb', 346, 250, true );
    add_image_size( 'hybrid-thumb', 208, 9999 );
    add_image_size( 'blogv2-thumb', 159, 126, true );
    add_image_size( 'blogv2bs-thumbbs', 454, 267, true );
    add_image_size( 'category-thumb-3', 454, 9999 );
    add_image_size( 'category-thumb-4', 60, 60, true );
    add_image_size( 'category-thumb-s', 940, 9999 );
    add_image_size( 'slide_post', 940, 420, true );
    add_image_size( 'blog_posts', 601, 9999 );
    add_image_size( 'thumb-blog', 983, 501, true );
    add_image_size( 'related-thumb', 134, 100, true );
    add_image_size( 'portoflio-thumb', 960, 487, true );
    add_image_size( 'portoflio-related-thumb', 216, 140, true );
    
    wp_link_pages( $args );
    posts_nav_link();
    the_tags();
    
    /********************** Tag Styles *******************************/
    
    function tag_style($args = array ()) {
    
             $args['smallest'] = 12;
    		 $args['largest'] = 12;
    		 $args['unit'] = 'px';
    		 $args['number'] = 25;
    		 return $args;
    		 }
    add_filter ('widget_tag_cloud_args', 'tag_style', 90);	
    
    /********************** Comments *******************************/
    
    if ( ! function_exists( 'mt_comment' ) ) :
    /**
    
     * @ Comments.php credit to Twenty Ten WordPress theme - http://wordpress.org/extend/themes/twentyten
     * @ Modified by Moonthemes
    
     */
    
    function mt_comment( $comment, $args, $depth ) {
    	$GLOBALS['comment'] = $comment;
    	switch ( $comment->comment_type ) :
    		case '' :
    	?>
    	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
    		<div id="comment-<?php comment_ID(); ?>">
    			<div class="comment-author vcard">
    				<?php echo get_avatar( $comment, 50 ); ?>
    				<?php printf( __( '%s <span class="says"></span>', 'mt' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
    			</div><!-- .comment-author .vcard -->
    			<?php if ( $comment->comment_approved == '0' ) : ?>
    				<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'mt' ); ?></em>
    				<br />
    			<?php endif; ?>
    
    			<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
    				<?php
    					/* translators: 1: date, 2: time */
    					printf( __( '%1$s at %2$s', 'mt' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'mt' ), ' ' );
    				?>
    				&middot; <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
    
    			</div><!-- .comment-meta .commentmetadata -->
    
    			<div class="comment-body"><?php comment_text(); ?></div>
    
    		</div><!-- #comment-##  -->
    
    	<?php
    			break;
    		case 'pingback'  :
    		case 'trackback' :
    	?>
    	<li class="post pingback">
    		<p><?php _e( 'Pingback:', 'mt' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'mt' ), ' ' ); ?></p>
    	<?php
    			break;
    	endswitch;
    }
    endif;
    
    // add filter to change the text of comment notes
    add_filter ('comment_form_defaults','comment_reform');
    
    function comment_reform($arg) {
        $arg['comment_notes_before'] = '<p class="comment-notes">' . __ ('Your email address and name are required fields marked') . '<span class="required2">' . __ ( ' * ' ) . '</span>' . '</p>';
    	return $arg;
    	}
    
    /*
    Plugin Name: Limit Posts
    Plugin URI: http://labitacora.net/comunBlog/limit-post.phps
    Description: Limits the displayed text length on the index page entries and generates a link to a page to read the full content if its bigger than the selected maximum length.
    Usage: the_content_limit($max_charaters, $more_link)
    Version: 1.1
    Author: Alfonso Sánchez-Paus Díaz y Julián Simón de Castro
    Author URI: http://labitacora.net/
    License: GPL
    Download URL: http://labitacora.net/comunBlog/limit-post.phps
    Make:
        In file index.php
        replace the_content()
        with the_content_limit(1000, "more")
    */
    
    function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
        $content = get_the_content($more_link_text, $stripteaser, $more_file);
        $content = apply_filters('the_content', $content);
        $content = str_replace(']]>', ']]>', $content);
        $content = strip_tags($content);
    
       if (strlen($_GET['p']) > 0) {
          echo "<p>";
          echo $content;
          echo "</p>";
       }
       else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
            $content = substr($content, 0, $espacio);
            $content = $content;
            echo "<p>";
            echo $content;
            echo "</p>";
       }
       else {
          echo "<p>";
          echo $content;
          echo "</p>";
       }
    }
    
    // Custom Pagination
    function mtpagi_pagination($pages = '', $range = 2)
    {
         $showitems = ($range * 2)+1;  
    
         global $paged;
         if(empty($paged)) $paged = 1;
    
         if($pages == '')
         {
             global $wp_query;
             $pages = $wp_query->max_num_pages;
             if(!$pages)
             {
                 $pages = 1;
             }
         }   
    
         if(1 != $pages)
         {
             echo "<div class='pagination'>";
             if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'><span class='previouspostslink'></span></a>";
             if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'><span class='first'></span></a>";
    
             for ($i=1; $i <= $pages; $i++)
             {
                 if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
                 {
                     echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
                 }
             }
    
             if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'><span class='nextpostslink'></span></a>";
             if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'><span class='last'></span></a>";
             echo "</div>n";
         }
    }
    
    ?>
  • Unknown's avatar

    Hi! Your question seems to be about WordPress custom coding and not about a WordPress.com blog. This forum is for WordPress.com support, and you should ask your question about custom post types in the WordPress.org volunteer-based forums at http://wordpress.org/support/

  • The topic ‘Need Help with Post Category Filtering’ is closed to new replies.