######################################################################################
# AnasayfaHaberBlok
######################################################################################
class AnasayfaHaberBlok extends WP_Widget {
function __construct() {
$widget_options = array( 'description' => 'Anasayfa haber blokları.' );
parent::WP_Widget(false,'(Anasayfa) Haber Blok', $widget_options );
}
function widget($args, $instance) {
extract($args);
$kategori = $instance['kategori'];
$tip = $instance['tip'];
$sayi = $instance['sayi'];
$renk = $instance['renk'];
if(empty($kategori)) {
$kategori = "";
}
if(empty($sayi)) {
$sayi = "4";
}
if(empty($renk)) {
$renk = "#D33532";
}
echo $before_widget;
?>
if($kategori) {
$kategori_baslik = get_cat_name($kategori);
$kategori_link = 'Tümü ';
} else {
$kategori_baslik = "Son Haberler";
}
?>
$i = 0;
query_posts("cat={$kategori}&showposts={$sayi}&");
while ( have_posts() ) : the_post();
global $post;
$i++;
?>
if ($i%2 == 0) {
echo '';
}
?>
endwhile;
wp_reset_query();
?>
echo $after_widget;
}
function update($new_instance, $old_instance) {
return $new_instance;
}
function form($instance) {
if(isset($instance['kategori'])) {
$kategori = $instance['kategori'];
}
if(isset($instance['sayi'])) {
$sayi = $instance['sayi'];
}
if(isset($instance['renk'])) {
$renk = $instance['renk'];
}
?>
Eğer kategori seçmezseniz son yazılar görünecektir.
type="text" id="get_field_id( 'renk' ) ;?>"
class="widefat" value="" name="get_field_name( 'renk' ) ;?>"
placeholder="#c0c0c0 gibi"
/>
Lütfen bir renk kodu giriniz. Varsayılan : #D33532.
}
}
register_widget( 'AnasayfaHaberBlok' );