• 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>
                        	<td>
                            <select name="slider_cat" id="slider_cat">
                            	<option>SELECT</option>
                            	<?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>';
    									else:
    									echo '<option value="'.$cat->term_id.'">'.$cat->name.'</option>';
    									endif;
    								endforeach;
    							?>

    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

    (@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.

    Thread Starter creativeliza

    (@creativeliza)

    Thanks, you are correct, it is for a slider, and also for the home page: http://www.therrestra.com/site

    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.