Support » Plugins » Hacks » posts to pull from subcategory

  • I have been working with a programmer on a custom theme. It is almost right but i want the home page to pull from posts within a subcategory of a category. here is the code in the functions.php

    <?php $prim_post_id = get_option('home_prime_slider'); ?>
                        	<th scope="row"><label for="pri_slider">Select The Category For Slider</label></th>
                            <select name="slider_cat" id="slider_cat">
                            	<?php  // Get all categories
    								$slider_cat_id = get_option('slider_category');
    								$args = array(
    									'type' => 'post',
    									'taxonomy'=> 'category'
    								$categories = get_categories( $args );
    								foreach ( $categories as $cat ):
    									if( $cat->term_id == $slider_cat_id ):
                                		echo '<option value="'.$cat->term_id.'" selected="selected">'.$cat->name.'</option>';
    									echo '<option value="'.$cat->term_id.'">'.$cat->name.'</option>';

    can anyone guide me as to how to adapt this to include subcategories of the main category?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz


    The code is displaying the categories in a drop down selection, it should be displaying all categories assigned to any posts, regardless if a sub category or not.

    It appears to be for configuring a slider, not your home page. To show posts from a particular category or sub category on your home page, assuming right now it is showing all posts, you need to alter the query to do so. See the ‘pre_get_posts‘ action documentation.

    Thanks, you are correct, it is for a slider, and also for the home page:

    I am not a programmer so I was hoping for an example of the code to change. I tried a few things but I am not a programmer so I keep getting errors.

    Basically I want it to include the child categories within the parent category.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘posts to pull from subcategory’ is closed to new replies.