Keyword

[SOLVED] Hide unused categories in front-end view

  • Robert Peterson
  • Robert Peterson's Avatar Topic Author
  • Offline
  • Junior Member
More
10 years 9 months ago #121985 by Robert Peterson
[SOLVED] Hide unused categories in front-end view was created by Robert Peterson
Hello, all! I'm trying to hide unused categories -- meaning, categories that a usergroup lacks access to -- on the front-end. I searched this forum and found this solution:

getk2.org/community/New-to-K2-Ask-here-first/139209-Frontend-Editing---Hide-Categories-which-are-disabled

... but it appears to be out of date. That solution seems to be for K2 v.2.4, while I'm using 2.6.7.

Can anyone offer any guidance for how to hide those unused categories? Thank you!

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 9 months ago #121986 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Hide unused categories in front-end view
You need a simple JS script like: stackoverflow.com/questions/1518216/jquery-remove-options-from-select

Just replace the [value="x"] with checking if the option is disabled.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
10 years 9 months ago - 10 years 9 months ago #121987 by Lefteris
Replied by Lefteris on topic Re: Hide unused categories in front-end view
The solution mentioned in the linked post will still work since it is only applied to CSS. It works in all modern browsers.

You can try to add this,

div#k2Frontend select#catid > option[disabled="disabled"] {display:none;}

to your k2.css file.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Robert Peterson
  • Robert Peterson's Avatar Topic Author
  • Offline
  • Junior Member
More
10 years 9 months ago #121988 by Robert Peterson
Replied by Robert Peterson on topic Re: Hide unused categories in front-end view
Hi, everyone! Thanks so much for the responses!

Yiota, I tried your CSS solution, cleared all my caches, and still no go. The categories are still appearing.

Krikor, thank you for the link! I'll give that a shot.

Can either of you tell me where that list of categories is generated? I've found the hook for the list in:

/com_k2/templates/Default/itemform.php

NOTE: I've added a template override for this file.

Here's the hook for the list of categories:
<td class="adminK2RightCol">
<?php echo $this->lists['categories']; ?>
</td>

But again -- that's only the hook. Where are the categories themselves generated? If I can adjust the markup for the categories themselves, I might be able to make this happen.


Thank you!!! :cheer:

Please Log in or Create an account to join the conversation.

  • Robert Peterson
  • Robert Peterson's Avatar Topic Author
  • Offline
  • Junior Member
More
10 years 9 months ago #121989 by Robert Peterson
Replied by Robert Peterson on topic Re: Hide unused categories in front-end view

Krikor Boghossian wrote: You need a simple JS script like: stackoverflow.com/questions/1518216/jquery-remove-options-from-select

Just replace the [value="x"] with checking if the option is disabled.


Krikor, I've been trying this solution with no effect. Here's where I'm placing the code:

[MYTEMPLATEFOLDER]/html/com_k2/templates/default/itemform.php

Is that where it should go?

Thank you!!!

b

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 9 months ago #121990 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Hide unused categories in front-end view
$K2('select[disabled="disabled"]').each(function() {
    $K2(this).remove();
});

You need to place this inside a document ready or window load function in order to work.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Robert Peterson
  • Robert Peterson's Avatar Topic Author
  • Offline
  • Junior Member
More
10 years 9 months ago #121991 by Robert Peterson
Replied by Robert Peterson on topic Re: Hide unused categories in front-end view

Krikor Boghossian wrote:

$K2('select[disabled="disabled"]').each(function() {
    $K2(this).remove();
});

You need to place this inside a document ready or window load function in order to work.


Krikor, I'm struggling to get the syntax right on this. Can I trouble you to show me how this would look inside a document ready? Here's what I have now:
<script>

$( document ).ready(function() {

$K2('select[disabled="disabled"]').each(function() {
$K2(this).remove();
});

</script>

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 9 months ago #121992 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Hide unused categories in front-end view
the $ might produce some conflicts. You should use $K2 instead.
$K2(document).ready(function() {
	$K2('select[disabled="disabled"]').each(function() {
		$K2(this).remove();
	});
});

let me know if that did the trick

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Robert Peterson
  • Robert Peterson's Avatar Topic Author
  • Offline
  • Junior Member
More
10 years 9 months ago #121993 by Robert Peterson
Replied by Robert Peterson on topic Re: Hide unused categories in front-end view
Krikor, that still doesn't seem to be working. I've placed the code near the top of this file in my template overrides:

[MYTEMPLATEFOLDER]/html/com_k2/templates/default/itemform.php

Is that where it should go?

Thank you again! :)

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 9 months ago #121994 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Hide unused categories in front-end view
Are you getting a JS error?

Actually the path is MYTEMPLATEFOLDER]/html/com_k2/default/itemform.php

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum