← WordPress

Thumbnail - Artigos Recentes

Lida 2831 vezes

Offline

Vitor Teixeira 
Membro
Mensagens 1527 Gostos 9
Feedback +21

Troféus totais: 29
Trófeus: (Ver todos)
Tenth year Anniversary Windows User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3

Na sidebar do Ser Anónimo, tenho um widget que mostra os Artigos Recentes, porém acho um pouco "despido" e queria adicionar ao lado dos artigos uma thumbnail, é possível? Alguém o sabe fazer?

Tema: Cleanmag
Link: www.seranonimo.info

Os melhores cumprimentos,
Vitor Teixeira.
Offline

Vitor Teixeira 
Membro
Mensagens 1527 Gostos 9
Feedback +21

Troféus totais: 29
Trófeus: (Ver todos)
Tenth year Anniversary Windows User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3

Ninguém?
Offline

rtbfreitas 
Equipa
Mensagens 1497 Gostos 9
Feedback +24

Troféus totais: 30
Trófeus: (Ver todos)
Windows User Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4

Tens de editar o código do widget e adicionar a thumbnail.
Offline

Vitor Teixeira 
Membro
Mensagens 1527 Gostos 9
Feedback +21

Troféus totais: 29
Trófeus: (Ver todos)
Tenth year Anniversary Windows User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3

Onde vou buscar o código do widget?

Depois ao editar posso usar o código do thumbnail dos artigos? ou terei de fazer um de novo?
Offline

rtbfreitas 
Equipa
Mensagens 1497 Gostos 9
Feedback +24

Troféus totais: 30
Trófeus: (Ver todos)
Windows User Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4

Se usares algum plugin deve estar na pasta desse plugin.

Sim, em principio poderás usar o código do thumbnail dos artigos...Estás a usar as thumbnails do WP ou custom?
Offline

Vitor Teixeira 
Membro
Mensagens 1527 Gostos 9
Feedback +21

Troféus totais: 29
Trófeus: (Ver todos)
Tenth year Anniversary Windows User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3

Não estou a usar nenhum plugin, já veio com o WP.

As Thumbnail é as default do WP.
Offline

rtbfreitas 
Equipa
Mensagens 1497 Gostos 9
Feedback +24

Troféus totais: 30
Trófeus: (Ver todos)
Windows User Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4

Os widget default do WP estão em wp-includes/default-widgets.php , mas o meu conselho é criar um no teu tema ou instalares um plugin que faça isso, porque se editares o default quando actualizares podes perder as alterações que faças.
Offline

victei 
Membro
Mensagens 17 Gostos 0
Troféus totais: 17
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 3 Level 2 Level 1 10 Posts First Post Karma Webmaster

Onde vou buscar o código do widget?

Depois ao editar posso usar o código do thumbnail dos artigos? ou terei de fazer um de novo?

Depende!

Se usas um plugin esta em plugins>>pasta do plugin
Se é da propria theme...pode estar em function.php ou noutro arquivo que a theme use...tipo themewidget.php

No wp podes fazer com que ele crie os thumbnail automaticamente quando crias um post... no arquivo function.php do theme deves la ter algo do genero:


...
/* Post Thumbnails */
add_theme_support('post-thumbnails');
...


Para adicionares os tamanhos que queres escreve no arquivo o seguinte:


...
/* Post Thumbnails */
add_theme_support('post-thumbnails');

add_image_size('featuredposts-thumbnail'140100TRUE)
...


assim, sempre que cries um post com thumbnail, é criado tambem um thumbnail com as medidas 140x100...

um abraço
Offline

Vitor Teixeira 
Membro
Mensagens 1527 Gostos 9
Feedback +21

Troféus totais: 29
Trófeus: (Ver todos)
Tenth year Anniversary Windows User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3

Optei por um plugin.
Nome: Better Recent Posts Widget

Obrigado aos que responderam!  :)

Podem fechar.
Offline

Fernando Augusto 
Membro
Mensagens 922 Gostos 0
Feedback +1

Troféus totais: 30
Trófeus: (Ver todos)
Linux User Mobile User Windows User Super Combination Combination Topic Starter Poll Voter Level 5 Level 4 Level 3

Se não quiseres plugin, experimenta isto.

No teu functions coloca

Código: (php) [Seleccione]

// Incluir custom widgets
require('includes/widget-posts-recentes.php');

e

Código: (php) [Seleccione]
// Activate post-image functionality (WP 2.9+)
if ( function_exists( 'add_theme_support' ) )
add_theme_support( 'post-thumbnails' );

// Featured images
if ( function_exists( 'add_image_size' ) ) {

// Tamanho da Imagem
add_image_size( 'small-thumbnail',  50, 50, true ); //Small thumbs
}

Caso já tenhas essa função no functions, apenas tens de colocar a partir de //Tamanho da Imagem

Cria o ficheiro widget-posts-recentes.php e coloca-o dentro da seguinte pasta (includes), com o seguinte código.

Código: (php) [Seleccione]
<?php
/******************************************
/* Widget Posts Recentes
******************************************/
class custom_recent_posts extends WP_Widget {
    
/** constructor */
    
function custom_recent_posts() {
        
parent::WP_Widget(false$name 'Posts Recentes com Thumbnails');
    }

    
/** @see WP_Widget::widget */
    
function widget($args$instance) {
        
extract$args );
        
$title apply_filters('widget_title'$instance['title']);
        
$number apply_filters('widget_title'$instance['number']);
        
$offset apply_filters('widget_title'$instance['offset']);
        
?>

              <?php echo $before_widget?>
                  <?php if ( $title )
                        echo 
$before_title $title $after_title?>

<ul class="widget-recent-posts clearfix">
<?php
global $post;
$tmp_post $post;
$args = array( 'numberposts' => $number'offset'=> $offset );
$myposts get_posts$args );
$count=0;
foreach( $myposts as $post ) : setup_postdata($post);
$count++;
?>

                                <?php if ( has_post_thumbnail() ) {  ?>
<li class="clearfix">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail('small-thumbnail');?></a>
<a href="<?php the_permalink(); ?>"><?php
$thetitle $post->post_title/* or you can use get_the_title() */
$getlength strlen($thetitle);
$thelength 20;
echo substr($thetitle0$thelength);
if ($getlength $thelength) echo "...";
?>

<span class="time">
<?php _e('Autor:'); ?>: <?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) ?> <?php _e('ago'); ?></span>
                                        </a>
</li>
                                    <?php ?>
<?php endforeach; ?>
<?php $post $tmp_post?>
</ul>
              <?php echo $after_widget?>
        <?php
    
}

    
/** @see WP_Widget::update */
    
function update($new_instance$old_instance) {
$instance $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['number'] = strip_tags($new_instance['number']);
$instance['offset'] = strip_tags($new_instance['offset']);
        return 
$instance;
    }

    
/** @see WP_Widget::form */
    
function form($instance) {
        
$title esc_attr($instance['title']);
        
$number esc_attr($instance['number']);
        
$offset esc_attr($instance['offset']);
        
?>

         <p>
          <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Título'); ?></label>
          <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title?>" />
        </p>
<p>
          <label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Quantos mostrar'); ?></label>
          <input class="widefat" id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number?>" />
        </p>
<p>
          <label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Offset (the number of posts to skip)'); ?></label>
          <input class="widefat" id="<?php echo $this->get_field_id('offset'); ?>" name="<?php echo $this->get_field_name('offset'); ?>" type="text" value="<?php echo $offset?>" />
        </p>
        <?php 
    
}


// class custom recent posts
// register Recent Posts widget
add_action('widgets_init'create_function('''return register_widget("custom_recent_posts");'));
?>