List categories in widget?
-
Is there a way to list the categories in a widget?
-
Hi vahost,
Yes, there is–we have an article about it here: http://businessdirectoryplugin.com/support-forum/faq/how-to-display-bd-categories-using-a-widget/
That Custom Taxonomies Menu Widget does seem pretty good.
I don’t see a way to exclude it from the front page that lists the categories, though. There doesn’t seem to be a unique identifier for just that page I can access in CSS to display:none.
Hi vahost,
I don’t know if that particular plugin supports what you’re looking to do–the exclusion of a widget on a page usually is at the template level, meaning there’s a special “front page” template and you either add or don’t add the widget there, and then there’s a “other pages” template that you can add it. That’s definitely beyond the scope of BD’s control either way, though.
Sure, I could create a simple function that excludes the widget from appearing when is_front_page() is true, for example. However, because BD does all its work from the same page, if I have BD on the front_page, it doesn’t just exclude the widget from the front_page. It also excludes the widget from ALL BD pages because BD uses just one WordPress page (in this case, the front page) to show BD’s stuff, whether it’s the list of categories page or one of the individual category or individual listing pages.
What I need is a unique identifier of some kind, such as <div id=”unique-identifier”></div> or something like that, which differentiates BD’s list of categories page from the other pages in BD. Is there one?
I’ll need to ask my developer that question. I’m not sure if something like that exists.
Here’s what my developer said:
He could use something like this (at the template level):
<?php global $wpbdp; $current_page = $wpbdp->views->get_current_action(); if ( ! $current_page ) { // This is not a BD page. } elseif ( $current_page == 'main' ) { // We're on BD's main page. } else { // We're on a different BD page. }Hope that helps.
Unfortunately, it white screens the site when I add it to my functions.php file. Even the following simplified code white screens the site:
global $wpbdp;
$current_page = $wpbdp->views->get_current_action();
if ( $current_page == ‘main’ ) {
// We’re on BD’s main page.
}I still say there should be unique identifiers in the HTML of the BD pages, just as there are with regular WordPress pages or posts, or even custom taxonomies like BD’s. BD does have unique identifiers in some cases, but not in all.
When I use Firebug to compare the complete CSS path to the widget on the category list page to the CSS path on any of the individual category or listing pages, the CSS path is identical, like this;
html body.home.page.page-id-4.page-template-default.logged-in.admin-bar.header-image.content-sidebar.windows.ie11.override.customize-support div.site-container div.site-inner div.content-sidebar-wrap aside.sidebar.sidebar-primary.widget-area section#sgr-custom-taxonomies-menu-2.widget.sgr-custom-taxonomies-menu div.widget-wrap {}The only time there’s differentiation is when I view the CSS path on a page 2, page 3, or whatever within a single category, like this:
html body.home.paged.page.page-id-4.page-template-default.logged-in.admin-bar.paged-2.page-paged-2.header-image.content-sidebar.windows.ie11.override.customize-support div.site-container div.site-inner div.content-sidebar-wrap aside.sidebar.sidebar-primary.widget-area section#sgr-custom-taxonomies-menu-2.widget.sgr-custom-taxonomies-menu div.widget-wrapWhy can’t your developer create unique identifiers on ALL of the BD pages, and not just some of them?
The function above will work, but only in template overrides–I’m not sure what your functions.php represents or when it gets included, so it may be running code that is not at the appropriate place or context. That would explain the white screen you’re getting. But instead of patching the symptom, maybe we need a broader view.
Let’s take a step back for a second here–what exactly are you trying to accomplish on the page? If I understood what your end goal is, I might have a better suggestion to go at it.
The goal is remarkably simple. I don’t want the categories in the widget created with the Custom Taxonomies Menu Widget plugin to appear on the same BD home page that ALSO shows all the categories.
I’m trying to show the categories on all of BD’s individual listing and individual category pages, but NOT on BD’s home page.
Does that make it clear enough?
Toward this goal, at your suggestion, I tried the Custom Taxonomies Menu Widget plugin, which satisfies nearly the entire need. The only problem is that the category list from the Custom Taxonomies Menu Widget plugin ALSO appears on the BD home page where the full list of categories already appears.
In other words, on the BD home page with the Custom Taxonomies Menu Widget plugin enabled, we get duplicated presentation of categories. Obviously, that’s not a good thing.
The simplest solution would be to hide the widget on the BD home page using the attribute display:none in CSS. However, there is no unique identifier in the HTML of the widget on that page to differentiate it from all the other BD pages, such as id=”widget-home” or something like that.
That’s why I’ve been asking for your plugin’s developer to add a differentiator of that kind to the BD home page.
OK–and which functions.php are you putting the PHP code in? (that’s a very common filename, so I need to know exactly where it’s going)
It’s the functions.php file that appears on the root level of a theme folder. I’m using Genesis Dynamik, but the same problem also occurs with the standard WordPress themes, such as Twenty Fourteen.
By the way, if you want an easy way to gain a fuller grasp of the scope of the problem, install the Display Widgets theme in a test instance of WordPress with BD installed. (https://ww.wp.xz.cn/plugins/display-widgets/)
The Display Widgets plugin enables you to select which pages or posts a widget will appear on. Try it with any widget, and you’ll see how easy it is to use. It works very nicely with every widget, plugin, or theme I’ve ever used. It’s a great plugin!
Now try Display Widgets with the Custom Taxonomies Menu Widget and select your directory names from the list. Then see if you can use Display Widget’s options to selectively show the widget on some, but not all, of your BD directory pages. You’ll find that you can set the setting, but it won’t behave as it does with other plugins, themes, widgets, etc.
The problem isn’t caused by the Custom Taxonomies Menu Widget. It works just fine with other custom taxonomies and the Display Widgets plugin. It’s only the BD custom taxonomy that causes issues and doesn’t work properly.
OK, so this sounds like a conflict between BD, Custom Taxonomies and the Display Widgets plugin.
We can try to reproduce this locally and then understand what the cause is here. Give us a bit to try that.
OK–I spoke with my developer, here’s what he had to say about it. It’s not actually a conflict–it’s a combination of how BD is implemented and how WP treats custom post types:
There is only one BD page (the main one) and as such, the other plugins (like Display Widgets) just see that. We, at the BD level, have a way to differentiate between a listing being shown or the main page or a category, but other plugins don’t.
That’s the problem with dispatching everything from one page using a short code. To WP (and other plugins) we are always displaying the same page. They can’t know if we are actually displaying a category, an individual listing, etc. The only way to do that would be to use the templates for custom post types (and taxonomies) but that means we are no longer in control of things.The customer itself was already familiar with this issue. He was right when he said the problem was with BD doing all of its work from within the same page. Until WP improves in this aspect the only solution would be to create a custom post type and taxonomy template–which has its own set of complications, like making customizations a nightmare for display. That means WP and other plugins now know when you’re looking at a taxonomy archive, single post, etc, but at the same time we lose integration with our modules, we can’t control what’s being displayed (fields, images, etc.) and it’s now up to users to create the templates matching their themes.
In short, we’re kind of stuck with a technical limitation here. We can add some indicators about BD pages for a future release, but it’s not in there today to be able to differentiate the way you’d like.
Thanks to your developer for clarifying. Yes, that’s pretty much what I thought must be happening.
A suggestion though: With respect, I think he’s overly cautious about “losing control” by using templates for custom taxonomies. This is exactly how WP has improved the power inherent in custom taxonomies. It’s just that your developer doesn’t like the improvement.
He writes, “…the only solution would be to create a custom post type and taxonomy template–which has its own set of complications, like making customizations a nightmare for display.”
A nightmare? I think that’s being a bit dramatic. Certainly, he’d use a default template of his own design for BD-out-of-the-box, but that doesn’t make it a nightmare if a user creates a different custom template. It creates power and opportunity for the community at large rather than keeping it in the exclusive hands of the plugin developer.
But even if he’s really stuck on the idea that there must be only one page to be shared by the entire directory (a concept, by the way, which stands in defiance of how WordPress has been developed over the years), he can still build HTML hooks in. Similar to the way WordPress has unique page IDs and includes them in the available classes and ID selectors, he can also use his own BD page numbering system to build classes or ID selectors that are BD-page-specific.
In other words, the problem here isn’t really a technical limitation as much it’s a plugin design limitation, one which he already has the tools in place to overcome.
Thanks for commenting here!
We’ve actually done those templates before. The “nightmare” comment is extraordinarily accurate, based on several months of experience with them unfortunately.
We had them in 2012 and the overwhelming feedback from having them boiled down to a few points:
– Too hard to customize for the “average person”
– A lot of work for the technically oriented person (a lot of templates)
– Theme integration out of the box was pretty bad
– A lot of support required to guide people through customizing for the most basic of thingsThe shortcode approach was our solution to control the output, integrate with the theme more easily and make it easier for 80% of the user base to work out of the box. We’ve added additional templates and CSS hooks since to add more flexibility, but we’re not perfect and aren’t the right fit for everybody.
While you may be a technically oriented person and completely comfortable doing all of those things, it turned out the majority of our users were not and the complaints mounted high and wide in those 12 months we had the solution you propose in place. After that, we switched to the shortcode output with some template overrides that you can put in place. People have reacted much more favorably since.
We have a plan right now we’re working on to change how the output works to add even better flexibility. I know the existing solution isn’t perfect for everyone.
The topic ‘List categories in widget?’ is closed to new replies.