Show only subcategories of the current category expanded in the category widget

Posted in: Newspaper
Post count: 21

Salutare!

I have a website that has many subcategories for some categories, so the default wordpress categories widget is shown in the sidebar in a very VERY long manner. The simplest solution would be for only the subcategories of the currently viewed category to be expanded.

I’ve tried three different plugins, but the result wasn’t ok, they’re styling was completely different than Newspaper theme’s style, so it looked ugly.

I’ve looked for a custom solution, and I have found that some changes must be made to the theme function.php

see here (Andrey Sapegin solution at the bottom)… https://wordpress.org/support/topic/show-subcategories-only-for-selected-category

and here… https://wordpress.org/support/topic/show-subcategories-only-of-a-selected-parent-category

Can you please guide me on implementing this solution? I also want to suggest this to be implemented by default in a future update of the theme, it would be a great addition.

Multumesc frumos 🙂

Post count: 6600

Hi,

First add this code: http://pastebin.com/gCpuLN8z to the functions.php file like this: http://screencast.com/t/8G4gk4zL

Then add this code: http://pastebin.com/ZDmuhYzH into single.php file, like this: http://screencast.com/t/kaP50qRvJAC

Use this custom css: http://screencast.com/t/qCDdkgMO

.block-titleee span {
background-color: #000000;
z-index: 1;
color: white;
font-family: 'Roboto Condensed', sans-serif;
padding: 3px 10px 3px 10px;
font-size: 20px;
line-height: 32px;
font-weight: normal;
margin-bottom: 10px;
}
.block-titleee {
border-bottom: 2px solid #000000;
}

.container_div .children {
margin-top: 10px;
}

Thanks

Post count: 21

Thank you very much for helping me, but it doesn’t work. I’ve done everything exactly as you mentioned above, I even named the categories widget ”My menu”.

Can I send you somehow some admin / Cpanel credentials so you can take a look? Please leave an email adress

Multumesc din nou 🙂

Post count: 6600

Hi,

I forgot to specify that after this changes you need to check this using the default sidebar position for your posts and also the default post template as the changes will affect only those conditions and you need to alter the others post templates as well as the other sidebars position on default post template if you want this in all you posts sidebars.
So please make sure you do this, should work as I have tested it. If still can’t manage to do it we suggest to get some one to do it for you as you need custom work for this and unfortunately the time and resources we have at this moment don’t allow us to offer custom work.

Sorry for the inconvenience!
Hope you understand!

Thanks for the message!

Post count: 21

Ok, everything is default, the sidebar is default (”Newspaper Default”) and also the position of it is default everywhere (on the right, as in the demo, and ”default” for every category in the theme’s settings, under the ”CUSTOM SIDEBAR + POSITION” setting everything is default).

Thanks for the solution, but a little sad it doesn’t work, with everything on default and also with the ”My menu” name for it. Also updated the theme, and redone all the settings above, and it still doesn’t work.

Or maybe I haven’t entered correctly the .css values? It was supposed to enter it in the theme settings under Theme Panel / Misc / Custom css / Your custom css, right?

Thanks again 🙂

Post count: 6600

Hi,

Yes, it should be added there, like this: http://screencast.com/t/Hxr50fZls
Please make this changes then send me your site’s URL so I can inspect it.

Thanks

Post count: 21

Then everything is exactly as you’ve said. Unfortunately the website isn’t live yet, it has a ”coming soon” plugin that hides the content.

Do you want some admin credentials to take a look? Please leave an email adress. Thanks 🙂

Post count: 21

Decided to make it live, so here’s the link… https://horoscopia.ro/

Hope you’ll find the reason why it doesn’t work. Thanks 🙂

Post count: 6600

Hi,

I have checked your site and several posts and seems that all of them use the post template 1 style so that could be why this doesn’t work for you.
Please make sure you make this changes to the post template style also, like this: http://screencast.com/t/vtTZfXtzY
This is how it works for me: http://screencast.com/t/E95NlZxvnK
You can also edit one post and set it to the default post template, like this: http://screencast.com/t/njgICBIq
Please let me know!

Thanks

Post count: 21

Also made that change and it still doesn’t work 🙁

So I need to delete it right? The categories widget I mean…

Thanks for all the help though 🙂

Post count: 6600

Hi,

You could try another way. Add this code:

<ul><?php wp_list_categories('orderby=name&include=25,26,27'); ?></ul>

…to the top of your sidebar in post page, like this: http://screencast.com/t/q41M8L7wf whwre 25,26,27 represent the ID’s of the subcategories you want to display in the sidebar.
So you have to add that code and replace 25,26,27 with the subcategories ID of your subcategories then use the default post page with post template “default” and sidebar on the right to check the result: http://screencast.com/t/tPDsadSpm3
Try it and let me know if you manage to do it.

Thanks

  • This reply was modified 11 years by Lucian.
Post count: 21

Thanks again. It kinda works, but only on posts pages, not also on categories pages / homepage – look here… https://horoscopia.ro/horoscop-berbec-tendinte-generale-2014/

However, the desired result was to show the categories expanded when the post was from that category. For example the post above was is from Horoscop 2014, that has 12 subcategories. Your code only shows the main categories everywhere, although the subcategories IDs were mentioned in the code.

Not to mention that although it wasn’t mentioned with its ID, the ”Featured” category is shown by default, which is also an undesireded result.

At the end of the day I’m going to revert all the changes to the files, and delete the categories widget. I hope you’ll consider implementing in a future update of the theme this funtionality by default in the theme. After all, your theme is targeted to heavy-content based sites, and the ability to show smartly the categories in the default wordpress categories widget is a must in my opinion.

Thank you for all the explanations, but I’m not very happy that after all these changes I ended up deleting that widget. Again, please strongly consider making this a default behaviour in your theme in a future update.

Post count: 6600

Hi,

Sorry for the inconvenience! I was trying to help you implement the solution that you found for this WordPress widget. I will add this on out feature requests list and we will consider it for future updates but we have to be very carefully though what we chose to implement as we have over 170 feature requests on our list so if more people will ask for this we will try to do it.

Thanks for the message!

Viewing 13 posts - 1 through 13 (of 13 total)
The forum ‘Newspaper’ is closed to new topics and replies.