Show Widgets by category
-
@a_5mith got me on the right track for this messy hack.... but it does the trick.
in the container of your widget give it an ID name, then check for the name of the page ( I copied and pasted from the actual url in my browser "xxxxxxxxx.com:8080**/category/5/real-money-gold-silver**" ) by @a_5mith 's suggestion to check for the condition, and then the dom to hide it if not the correct page. Everything is self contained in the container.
<div id="gold" class="panel panel-default"><div class="panel-body">{body}</div>
<script>
if (ajaxify.currentPage !== 'category/5/real-money-gold-silver') {
document.getElementById("gold").style.display = 'none';
}
</script></div>Thanks for the help.... I hope this becomes easier in the future. Each Category has a targeted audience and the sidebars should reflect that. What a great product!
Rich
-
!== means
is not equal to
== means
is equal to
I just copied some code of mine and removed the non essential bits. Missed the !
If you have more than one category you want to do this for, I would set them all to display none by default, and then use is equal to to set the style to display block.
-
@a_5mith said:
!== means
is not equal to
== means
is equal to
I just copied some code of mine and removed the non essential bits. Missed the !
If you have more than one category you want to do this for, I would set them all to display none by default, and then use is equal to to set the style to display block.
Thanks... I know that. I was just wondering Why != instead of =. Anyway, in this case very thing is visible 'unless' it is the correct page, instead of everything 'invisible' and display only when the page is the correct page.
-
Hi, I tried this but it didn't work for me which I found to be very strange as this sort of thing works all the time on other javascript based sites.
Perhaps I am missing some logic, as it either displays on all pages or it does not show at all, but never for the page I want it to work for.I will keep playing with it too see if I am missing something...
-
This post is deleted!
-
Maybe this can help someone:
You can also use jquery:
This would go into the HTML widget:
<span class="offtopic_forbidden">Off-topic is strictly forbidden.</span> <script> if (ajaxify.currentPage != 'category/14/staff-recruitment') { $('.offtopic_forbidden').hide() } </script>
And this would be the container:
<div class="alert ui-draggable-handle alert-danger offtopic_forbidden">{{body}}</div>
Adjust 'category/14/staff-recruitment' to your needs.
-
$('.offtopic_forbidden')
is a jquery selector, it selects the DOM element with the class .offtopic_forbidden -
The function .hide() hides it.
Additional info:
-
You can use another type of container, but be sure to add the class to it.
-
You can also rename
offtopic_forbidden
to your needs.
-
-
@julian have you added this feature on the ACP widgets page?
We want each category to have its own dedicated widget, we will put a short description on top of each widget to explain what each category is about. Please let me know its very imp for us.
-
@faizanzahid This has been available for some time now.
-
@baris is it possible to add a widget that is topic specific?
I want certain announcements to show up in each page of a topic (either at the top of the page or at the bottom). It is not category or sub-category specific announcement, rather it is topic specific...
would it be possible to implement such widget? (If it is, I can make a github issue)
(edit: Currently, I add topic related announcements as post to the topic... However, if topic has 30-40 pages, it is just disappearing after certain time, I am trying to solve this problem)