Hi. We run a tech blog using WordPress and want to hide posts from certain category on the homepage. My theme developer replied to my email saying... ==== For this you would need to modify the WP_Query function in the file \functions\newstrick-blog-widget.php http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters ==== I checked the link and found this for my need. ==== $query = new WP_Query( 'cat=-12,-34,-56' ); ==== But I do not know where to add this line in my file below. } function widget($args,$instance){ extract($args); global $data, $post, $wp_query, $query; $ct_num_blog_posts = $instance['ct_num_blog_posts']; //$categories = $instance['categories']; $title = $instance['title']; $pagination_type = $instance['pagination_type']; $show_image = isset($instance['show_image']) ? 'true' : 'false'; $show_likes = isset($instance['show_likes']) ? 'true' : 'false'; $show_comments = isset($instance['show_comments']) ? 'true' : 'false'; $show_views = isset($instance['show_views']) ? 'true' : 'false'; $show_date = isset($instance['show_date']) ? 'true' : 'false'; $show_category = isset($instance['show_category']) ? 'true' : 'false'; $excerpt_lenght = $instance['excerpt_lenght']; $video_height = $instance['video_height']; $widget_width = $instance['widget_width']; $background = $instance['background']; $background_title = $instance['background_title']; $divider_type = $instance['divider_type']; // Get number of posts to display from Theme Options $blog_num_posts = stripslashes( $data['ct_blog_num_posts'] ); $max = 0; $count_posts = wp_count_posts(); $ct_post_count = $count_posts->publish; $max = ceil ($ct_post_count / $blog_num_posts); /* Before widget (defined by themes). */ if ( $title ){ echo "\n<!-- START BLOG WIDGET -->\n"; echo '<div class="' . $widget_width . '"><div class="widget ct-blog-widget margin-30t box border-1px bottom-shadow clearfix" style="background:' . $background . ';">'; echo '<div class="widget-title bottom-shadow" style="background:' . $background_title .';"><h2>' . $title . '</h2><div class="arrow-down" style="border-top-color:' . $background_title . ';"></div><!-- .arrow-down --><div class="plus"><span></span></div><!-- .plus --></div><!-- widget-title -->'; } else { echo "\n<!-- START BLOG WIDGET -->\n"; echo '<div class="' . $widget_width . '"><div class="widget margin-30t box border-1px bottom-shadow clearfix" style="background:' . $background . ';padding-top: 20px;">'; } ?> <?php if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } elseif ( get_query_var('page') ) { $paged = get_query_var('page'); } else { $paged = 1; } if ( !function_exists( 'ct_blog_pagination' ) ) { function ct_blog_pagination($pages = '', $range = 4) { $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 clearfix\"><span>Page ".$paged." of ".$pages."</span>"; if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>« First</a>"; if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹ Previous</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)."\">Next ›</a>"; if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last »</a>"; echo "</div>\n"; } } } // Check if Load More Button if ( $pagination_type == 'load_more' ) : wp_enqueue_script( 'pbd-alp-load-posts', get_template_directory_uri() . '/js/load-posts.js', array('jquery'), '1.0', true ); // Add some parameters for the JS. wp_localize_script( 'pbd-alp-load-posts', 'pbd_alp', array( 'startPage' => $paged, 'maxPages' => $max, 'nextLink' => next_posts($max, false) ) ); endif; $recent_posts = new WP_Query(array( 'posts_per_page' => $blog_num_posts, 'paged' => $paged, 'post_type' => 'post' //'cat' => $categories PHP: Can someone please help. Thanks in advance.
If youre trying to display posts from only those categories, depending on where you want them, I'd say you need to make a new template page and find the similar code in that page or the and replace it. Something similar to this: http://wordpress.org/support/topic/show-posts-of-a-certain-category-on-a-page Read the last post there. There's a WP_query code near the top of the code that user posted. Here's the code I'm referring to. <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $the_query = new WP_Query('cat=36&paged='.$paged.'&showposts=30&orderby=post_date&order=desc'); while ($the_query->have_posts()) : $the_query->the_post(); $do_not_duplicate = $post->ID; ?>