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
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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.