simcoweb Posted December 14, 2010 Share Posted December 14, 2010 Here's what i'm looking to do. By default when you click on a 'category' link in the menu it takes you to a page that displays the posts of that category. That's ok for the 'child' categories but for the main 'parent' category i'd like it to display the child categories as links. For example, my categories menu is like this: Chapters (main parent category) - Chapter One (child of main parent) -- Sub Chapter One (child of child) - Chapter Two (child of main parent) -- Sub Chapter of Two (child of child) etc. Therefore 'Chapters' is what displays in the main site category menu (when moused over it drops down to display the child categories). When someone clicks on the actual 'Chapters' title it goes to a page that displays ALL the posts of ALL the child chapters. What I want it to do is display the child chapters in a <ul> as clickable links. Wordpress has some available functions for this. For example, wp_list_categories() does just that. But, it lists ALL the categories including the child/child ones which I don't want. Plus, it lists Chapters as a category as well which is redundant. There's also the ability to modify the category.php file and use their 'loop' technique to have is set where 'if' this category is selected 'do this'. That's the point where i'm going to need some assistance. This appears to be the easiest way to go. An example of how it should work using plain text logic is: if (is_category('Category A')) { wp_list_categories(exclude=category_a); ?> Crude and incorrect syntax I know, but basically just to show what the results should be. When the category name Chapters is clicked then display the list of categories in a ul but exclude Chapters from the display. To carry it a bit further, just show the children of Chapters and not the children of the children. Thanking everyone in advance for your time! Quote Link to comment Share on other sites More sharing options...
prathikraj Posted December 16, 2010 Share Posted December 16, 2010 Why don't you try if (get_category_parents($cat,FALSE,"") == $cat) { //Do no display posts } else { //Display the posts } Quote Link to comment Share on other sites More sharing options...
simcoweb Posted December 16, 2010 Author Share Posted December 16, 2010 First, thanks for the post. Regarding your suggestion, would this need to replace any of the current functions in the category.php file? Or, be an addition to? Quote Link to comment Share on other sites More sharing options...
sgchris Posted December 17, 2010 Share Posted December 17, 2010 You can check in index.php file what script/file is running now. in your case you should check whether it's "category.php". Once you know that the page is category (is_category()), you may check what category it is and check manually thru the database if it's child or parent category global $wpdb; $res = $wpdb->get_results('....'); // write a query which checks if the category is child or parent Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.