function widget($args, $instance)
 {
     extract($args);
     echo $before_widget;
     if ($instance['title']) {
         echo $before_title . apply_filters('widget_title', $instance['title']) . $after_title;
     }
     global $width_widget_categories, $height_widget_categories;
     $widget_id = $args['widget_id'];
     $width = $width_widget_categories;
     $height = $height_widget_categories;
     $only_these = $instance['only_these'];
     $size_string = 'my_size_widget';
     //--------------------------------------------------
     $terms_k = get_terms("job_cat", "parent=0&hide_empty=0");
     global $wpdb;
     $arr = array();
     if ($only_these == "1") {
         $terms = array();
         foreach ($terms_k as $trm) {
             if ($instance['term_' . $trm->term_id] == $trm->term_id) {
                 array_push($terms, $trm);
             }
         }
     }
     //-----------------------------
     if (count($terms) < count($terms_k)) {
         $disp_btn = 1;
     } else {
         $disp_btn = 0;
     }
     $count = count($terms);
     $i = 0;
     if ($count > 0) {
         // echo '<style>#'.$widget_id.' .my_image_div_cat_name { width: '.round(100/$nr).'%}</style>';
         foreach ($terms as $term) {
             $pricerrtheme_get_cat_pic_attached = pricerrtheme_get_cat_pic_attached($term->term_id);
             $link = get_term_link($term->slug, "job_cat");
             $image = pricerrtheme_generate_thumb3($pricerrtheme_get_cat_pic_attached, 'my_category_image_thing');
             echo '<div class="my_category_image_holder"><div class="my_image_div">';
             echo '<a href="' . $link . '">';
             echo '<img src="' . $image . '" width="' . $width . '" height="' . $height . '" />';
             echo '</a></div>';
             echo '<div class="my_image_div_cat_name"><div class="padd10">';
             echo '<a href="' . $link . '">' . $term->name . '</a>';
             echo '</div></div>';
             echo '</div>';
         }
         //=========================================================================
         if ($disp_btn == 1) {
             echo '<div class="see-more-tax"><b><a href="' . get_permalink(get_option('PricerrTheme_all_categories_page_id')) . '">' . __('See More Categories', 'PricerrTheme') . '</a></b></div>';
         }
     } else {
         _e('There are no categories defined.', 'PricerrTheme');
     }
     echo $after_widget;
 }
Example #2
0
function PricerrTheme_category_images()
{
    $id_icon = 'icon-options-general-img';
    $ttl_of_stuff = 'PricerrTheme - ' . __('Category Images', 'PricerrTheme');
    global $menu_admin_pricerrtheme_theme_bull;
    //------------------------------------------------------
    $arr = array("yes" => __("Yes", 'PricerrTheme'), "no" => __("No", 'PricerrTheme'));
    echo '<div class="wrap">';
    echo '<div class="icon32" id="' . $id_icon . '"><br/></div>';
    echo '<h2 class="my_title_class_sitemile">' . $ttl_of_stuff . '</h2>';
    ?>
    
     <?php 
    if (isset($_POST['set_category_image'])) {
        $category_id = $_POST['category_id'];
        $category_image = $_POST['category_image'];
        if (!empty($_FILES['category_image']['name'])) {
            $upload_overrides = array('test_form' => false);
            $uploaded_file = wp_handle_upload($_FILES['category_image'], $upload_overrides);
            $file_name_and_location = $uploaded_file['file'];
            $file_title_for_media_library = $_FILES['category_image']['name'];
            $arr_file_type = wp_check_filetype(basename($_FILES['category_image']['name']));
            $uploaded_file_type = $arr_file_type['type'];
            if ($uploaded_file_type == "image/png" or $uploaded_file_type == "image/jpg" or $uploaded_file_type == "image/jpeg" or $uploaded_file_type == "image/gif") {
                $attachment = array('post_mime_type' => $uploaded_file_type, 'post_title' => addslashes($file_title_for_media_library), 'post_content' => '', 'post_status' => 'inherit', 'post_parent' => 0, 'post_author' => $cid);
                $attach_id = wp_insert_attachment($attachment, $file_name_and_location, 0);
                $attach_data = wp_generate_attachment_metadata($attach_id, $file_name_and_location);
                wp_update_attachment_metadata($attach_id, $attach_data);
                update_post_meta($attach_id, 'category_image', $category_id);
            }
            echo '<div class="saved_thing">' . __('Image attached. Done.', 'PricerrTheme') . '</div>';
        } else {
            echo '<div class="saved_thing">' . __('Please select an image.', 'PricerrTheme') . '</div>';
        }
    }
    ?>
    
    	<style>
		
		.crme_brullet
		{
			padding:2px;
			background:white;
			border:1px solid #ccc;	
		}
		
		</style>
        
            
              <script type="text/javascript">
	
				function delete_this_my_pic(id)
				{
					 $.ajax({
									method: 'get',
									url : '<?php 
    echo get_bloginfo('siteurl');
    ?>
/index.php?_ad_delete_pid='+id,
									dataType : 'text',
									success: function (text) {   window.location.reload();  
									
									return false;
									}
								 });
					  //alert("a");
					  
					  return false;
				
				}
				
			</script>
				
    
    	  <div id="usual2" class="usual"> 
          <ul> 
            <li><a href="#tabs1"><?php 
    _e('Set Images', 'PricerrTheme');
    ?>
</a></li> 
          </ul>
         
           <div id="tabs1">
           <?php 
    $categories = get_terms('job_cat', array('parent' => '0', 'hide_empty' => 0));
    if (count($categories) > 0) {
        ?>
           
           <table class="sitemile-table" width="650">
           <tr>
            	<td><strong><?php 
        echo __('Category Name', 'PricerrTheme');
        ?>
</strong></td>
            	<td><strong><?php 
        echo __('Upload Picture', 'PricerrTheme');
        ?>
</strong></td>
            	<td><strong><?php 
        echo __('Current Picture', 'PricerrTheme');
        ?>
</strong></td>
            </tr>
            
            
           <?php 
        foreach ($categories as $cat) {
            $pricerrtheme_get_cat_pic_attached = pricerrtheme_get_cat_pic_attached($cat->term_id);
            ?>
           	
            <form method="post" enctype="multipart/form-data"><input type="hidden" value="<?php 
            echo $cat->term_id;
            ?>
" name="category_id" />
           	<tr>
            	<td><?php 
            echo $cat->name;
            ?>
</td>
            	<td><?php 
            if ($pricerrtheme_get_cat_pic_attached == false) {
                ?>
                
                	<input type="file" name="category_image" size="20" />
                
                <?php 
            } else {
                ?>
                	<?php 
                _e('Picture attached already.', 'PricerrTheme');
                ?>
                <?php 
            }
            ?>
                </td>
            	<td>
                
                <?php 
            if ($pricerrtheme_get_cat_pic_attached == false) {
                ?>
                
                	 <input type="submit" name="set_category_image" size="20" value="<?php 
                _e('Upload Image', 'PricerrTheme');
                ?>
" />
                
                <?php 
            } else {
                ?>
                		
                        <img src="<?php 
                echo pricerrtheme_generate_thumb2($pricerrtheme_get_cat_pic_attached, 45, 35);
                ?>
" width="45" height="35" class="crme_brullet" />
                         <a href="" onclick="return delete_this_my_pic('<?php 
                echo $pricerrtheme_get_cat_pic_attached;
                ?>
')"><img src="<?php 
                bloginfo('template_url');
                ?>
/images/delete.gif" border="0" /></a>
                <?php 
            }
            ?>
                
                </td>
            </tr>
           </form>
           
           
           <?php 
        }
        ?>
           
           </table>
           <?php 
    }
    ?>
           
           </div> 
    
    
    <?php 
    echo '</div>';
}