Jump to content

A little Wordpress help, please


simcoweb

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/221694-a-little-wordpress-help-please/
Share on other sites

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

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.