Suporte » Desenvolvendo com WordPress » criar uma widgets

  • Resolvido ronaldy

    (@ronaldy)


    bom galera gostaria de saber como faço pra criar uma widgets estilo a encontrada nesse site catraca livre para gerenciar.
    nesse site tem um video de demostração da criação do catraca livre pelo pessoal da hacklab, cheguei a entra em contato com eles pra saber se era uma plugin, porem mim respoderam dizendo que não era e o codigo não estava disponibilizado para o publico.

    http://hacklab.com.br/portfolio/web/catraca-livre/

Visualizando 1 resposta (de um total de 1)
  • Salve Ronaldy,

    Aqueles widgets não estão disponíveis porque eles são muito específicos para o catraca e precisaria ainda de muito trabalho para deixa-los genericos o suficiente para ser um plugin publico..

    Mas de qq maneira ponho aqui o código base deles pra que possa servir de base pra quem quiser fazer widgets parecidos.. (Vc ainda vai precisar fazer CSS pra ele)

    abs

    <?php
    
    class Category_home extends WP_Widget {
    	function Category_home() {
    		$widget_ops = array('classname' => 'category_home', 'description' => 'Destaques de 1 Categoria em 1 coluna' );
    		parent::WP_Widget('category_home', '1 Categoria', $widget_ops);
    	}
    
    	function widget($args, $options) {
    
            global $wpdb;
            ?>
                <link rel="stylesheet" href="<?php echo WP_CONTENT_URL; ?>/themes/eletro/includes/widget_categories/category-widget.css" type="text/css" media="screen" />
            <?php
            extract($args);
    
    		if (!is_array($options) || !isset($options['cat']))
                return;
    
            $posts = new WP_Query('cat=' . $options['cat'] . '&orderby=date&order=DESC&showposts='.$options['numPosts'].'&offset='.$options['offset']);
    
    		echo ' <div class="category-widget">';
    	        if ($posts->have_posts()) {
    	        	$cat = get_category($options['cat']);
    	        	$parent_category = get_category($cat->parent);
    
                    $css_class = $cat->slug;
    	        	if($options['showCatName']=='sim'){
    	        		echo "<div class='widget_title'>";
    	        			echo '<h1 style="border-bottom: 4px solid ' . $options['color'] . ';"><a href=" '. get_category_link($cat->term_id) . '"  style="color:' . $options['color'] . '">'. $cat->name .'</a></h1>';
    	        		echo "</div>";
    	        	}
    
    	        	$i = 0;  
    
    	            while ($posts->have_posts()) :
    		            $posts->the_post();
    
                        $id = get_the_ID();
                        $query = "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_parent='$id' AND menu_order='1'" ;
                        $attachments = $wpdb->get_results($query);
                        if(empty($attachments[0]->ID)) {
                            $query = "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_parent='$id' AND menu_order='0'" ;
                            $attachments = $wpdb->get_results($query);
                        }
    	                if ($options['withPicture']) echo wp_get_attachment_image( $attachments[0]->ID , 'full');
    			        echo  '<h2><a href="'.get_permalink().'">';
                            the_title();
    	                echo  '</a></h2>';
    	                if ($options['showPostText']) echo '<p>' . the_excerpt() . '</p>';
    	                $i ++;
    	            endwhile;
    
    	        }
    	     echo ' </div>';
    
    	}
    
    	function form($options) {
            echo '<div class="eletro_widgets_control_row">';
    
                echo '<h3>Configurações da categoria</h3>';
    
                echo '<p>';
                    echo '<label for="' . $this->get_field_name('cat') . '">Selecione a categoria: </label>';
                            wp_dropdown_categories(array(
         		               'order' => 'ASC',
         		               'name' => $this->get_field_name('cat'),
         		               'selected' => $options['cat'],
         		               'id' => 'cat',
         		           ));
                echo '</p>';
    
                $showCatName = ($options['showCatName'] == 'sim') ? 'checked' : '';
    
                echo '<p>';
                    echo "<input type='checkbox' value='sim' $showCatName name='{$this->get_field_name('showCatName')}' id='{$this->get_field_name('showCatName')}' />";
                    echo "<label for='" . $this->get_field_name('showCatName') . "'>Exibir nome das categorias</label>";
                echo '</p>';
    
                echo "<p>
    				<label for='" . $this->get_field_name('color') . "'>
    					Cor do título:<input name='" . $this->get_field_name('color') . "' value='{$options['color']}' />
    				</label>
    			</p>";
    
            echo '</div>';
    
            echo '<div class="eletro_widgets_control_row">';
    
                echo '<h3>Configurações dos posts</h3>';
    
                $numSelected = array($options['numPosts'] => 'selected');
    
                echo '<p>';
                    echo '<label for="' . $this->get_field_name('numPosts') . '">Nº de posts: </label>';
                    echo '<select id="' . $this->get_field_name('numPosts') . '" name="' . $this->get_field_name('numPosts') . '">';
                        for ($i=1; $i<11; $i++) {
        	                echo "<option value='$i' {$numSelected[$i]}>$i</option>";
        	            }
    	            echo '</select>';
    
    	            echo "<label  for='" . $this->get_field_name('offset') . "'>Pular</label>";
                    echo "<input type='text' size='1' value='{$options['offset']}'  name='{$this->get_field_name('offset')}' id='{$this->get_field_name('offset')}' />posts";
                echo '</p>';
    
                $withPicture = ($options['withPicture'] == 'sim') ? 'checked' : '';
                echo "<p>";
                    echo "<input type='checkbox' value='sim'  $withPicture id='{$this->get_field_name('withPicture')}'  name='{$this->get_field_name('withPicture')}' />";
                    echo "<label for=\"{$this->get_field_name('withPicture')}\">Exibir Imagem</label>";
                echo "</p>";
    
                $showPostText = ($options['showPostText'] == 'sim') ? 'checked' : '';
    
                echo "<p>";
                    echo "<input type='checkbox' value='sim'  $showPostText id='{$this->get_field_name('showPostText')}'  name='{$this->get_field_name('showPostText')}' />";
                    echo "<label for=\"{$this->get_field_name('showPostText')}\">Exibir texto do post</label>";
                echo "</p>";
    
            echo '</div>';
    
            if(!isset($options['offset']) || $options['offset'] < 1)
                $options['offset'] = 0;
    
        }
    
    	function update($new_instance, $old_instance){
    
        	if(!isset($new_instance['showPostText'])){
        		$new_instance['showPostText'] = 'não';
        	}
    
    	    if(!isset($new_instance['showCatName'])){
                $new_instance['showCatName'] = 'não';
            }
    
        	if(!isset($new_instance['offset']) )
              $new_instance['offset'] = 0;
        	return $new_instance;
    
        }
    
    } // WIDGET Category_home END
    
    function widget_category_home_register() {
    	register_widget("Category_home");
    }
    
    add_action('widgets_init', 'widget_category_home_register');
    
    ?>
Visualizando 1 resposta (de um total de 1)
  • O tópico ‘criar uma widgets’ está fechado para novas respostas.