Jump to content

Hide subcategories (widget)


potski

Recommended Posts

Greetings,

So I am working on making a widget, I have the option to hide categories from it. The list with options of what to hide consist of both categories and subcategories. Now, the problem is, if I tick a main category then all subcategories will automatically be shown also. Meaning nothing will be hidden. If I only tick subcategories without its parent, well then everything will be shown on the page as long as its parent is ticked. Any ideas on how I can enable hiding subcategories while showing its parent?

<p>
			<label for="<?php echo $this->get_field_id('nr_rows'); ?>"><?php _e('Only show cities below'); ?>:</label>
			<?php echo '<input type="checkbox" name="'.$this->get_field_name('only_these').'"  value="1" '.(
	 $instance['only_these'] == "1" ? ' checked="checked" ' : "" ).' /> '; ?>
		</p>

        <p>
			<label for="<?php echo $this->get_field_id('nr_rows'); ?>"><?php _e('Cities to show'); ?>:</label>

                <div style=" width:220px;
    height:180px;
    background-color:#ffffff;
    overflow:auto;border:1px solid #ccc">
     <?php

	 $terms = get_terms("ad_city","ad_city=0&hide_empty=0");
	 foreach ( $terms as $term ) {

	 echo '<input type="checkbox" name="'.$this->get_field_name('term_'.$term->term_id).'"  value="'.$term->term_id.'" '.(
	 $instance['term_'.$term->term_id] == $term->term_id ? ' checked="checked" ' : "" ).' /> ';
	 echo $term->name.'<br/>';

Any help would be much appreciated :-)

Link to comment
Share on other sites

There's no way to help you with what you have posted. All you have provided is some code to create the form. There is nothing in that code that has logic to show/hide anything that I can see. I have no idea if you have PHP or JavaScript code to do the show/hide functionality.

Link to comment
Share on other sites

Hmm okay well that clears something up lol.

 

How about this:

		 if(count($terms) < count($terms_k)) $disp_btn = 1;
		else $disp_btn = 0;
		 
		 
		$count = count($terms); $i = 0;
		if ( $count > 0 ){
		     echo "<ul id='location-stuff'>";
		     foreach ( $terms as $term ) {
		       
			   if($i%$nr == 0) echo "<li>";
		       $total_ads = 0;
			   $terms2 = '';
			   	$terms2 = get_terms("city","parent=".$term->term_id."&hide_empty=0");
			

			   $mese2 = '';
			   if($terms2 && $only_parents == false)
				{
					
					foreach ( $terms2 as $term2 ) 
					{

I tried playing with this line: if($terms2 && $only_parents == false). Like this, then all categories and subcategories show up. I tried replacing only_parents it to only_these but it didn't have much of an impact. I guess it needs a second command?

Edited by potski
Link to comment
Share on other sites

Attached the full PHP file. Should have done that earlier.

 

 

Changing $terms = get_terms("ad_city","parent=0&hide_empty=0"); to $terms = get_terms("ad_city","ad_city=0&hide_empty=0"); will change the options from only parents to both categories and subcategories but still same problem -> subcategories can't be hidden if its parent is ticked.

widget6.php

Link to comment
Share on other sites

Let's start with the basics:

 

So I am working on making a widget,

 

You then posted code which clearly is part of some ecosystem (Wordpress apparently?) which you didn't write nor understand.

 

You'll get a lot farther providing some transparency.  It would have been better if you started with something like this?

 

"Hello.  I have a wordpress site, and I found this widget code which is close to what I want.  It's part of "xyz" package (linked to original).

What I would like to do is make something similar but with these differences.

Some screenshots or mockups would be helpful.

 

 

Some fundamentals seem to be in order.

 

Native user interface interactivity is accomplished via javascript, perhaps in concert with some ajax. Just because you found something that appears to be close to what you want doesn't mean that there are hooks or options built into it to suddenly expose options you wish the original interface has but you haven't found yet.

 

Consider this some friendly advice -- start with brutal honesty, and a lot more information about what you are trying to achieve and why, rather than throwing out some code you didn't write, and obfuscating the source and ecosystem it belongs to.

 

People here who most likely could help you do coding for a living. They aren't here to customize code for free. This forum exists to help others learn to program and help themselves by doing so.

Link to comment
Share on other sites

Duly noted. Thanks for speaking your mind about it. 

 

I will try to look up its javascript and modify it from there. And yes it is a widget from a Wordpress theme that is discontinued (no support for it anymore so trying to figure it out whilst learning).

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.