• 20-03-2024, 07:39:19
    #1
    Merhaba konum sadece yardım almak içindir. Basit bir sorum olacak kendim çözemedim. Dinamik bir widget hazırlıyorum. Alttaki kodda Araba Yarışı yazan alan kategori ismi o alana değişken eklemek istiyorum. Ama nasıl yapacağımı anlamadım. Değişken eklediğimde kod olarak gelmiyor. düz yazı gibi cıkıyor editörde " tırnak ekledim olmadı acaba sorun nedir.


    <?php
                        query_posts("category_name=Araba Yarisi&posts_per_page=5");
                        while(have_posts()) : the_post(); ?>
  • 21-03-2024, 00:19:42
    #2
    Kos koca forumdan bir cevap çıkmadı. R10 halbuki ticaret forumundan çok yardımlaşma forumudur. Neyse sorunu kendim çmzdüm özel bir fonksyion yazmak gerekiyormus. Aynı soruna takılanlar için fonksiyon altta.

        /**
         * Display widget
         */
        function widget( $args, $instance ) {
            $instance = wp_parse_args( $instance, $this->defaults );
            extract( $instance );
            extract( $args );        
            $query_args = array(
                'post_type' => 'post',
                'posts_per_page' => intval($count)
            );
            if ( !empty( $category ) )
                $query_args['tax_query'] = array(
                    array(
                        'taxonomy' => 'category',
                        'terms'    => $category,
                    ),
                );      
            if ($ids !=  '')       {
                $query_args['post__in'] = explode(",",$ids);
                 $query_args['orderby'] = 'post__in';
            }
            $flat_post = new WP_Query( $query_args );
            $classes[] = 'recent-news';
            echo wp_kses_post( $before_widget );
            if ( !empty($title) ) { echo wp_kses_post($before_title).esc_html($title).wp_kses_post($after_title); } ?>        
            <ul class="<?php echo esc_attr(implode(' ', $classes)) ;?> clearfix">  
            <?php if ( $flat_post->have_posts() ) : ?>
                <?php while ( $flat_post->have_posts() ) : $flat_post->the_post(); ?>
                    <li class="clearfix">       
                        <div class="thumb">
                            <span class="overlay-pop"></span>
                            <a href="<?php the_permalink(); ?>">
                            <?php 
                            the_post_thumbnail( 'thumbnail' );
                            ?>
                            </a>
                        </div>                                    
                        <div class="text">
                            <?php if ( $show_date ) : ?>
                            <time class="post-date" datetime="<?php esc_attr(the_time( 'c' )); ?>"><?php the_time( 'F d, Y' ); ?></time>
                            <?php endif; ?>  
                            <h6><a href="<?php echo esc_url( get_permalink() ); ?>" rel="bookmark"><?php the_title(); ?></a></h6> 
                            <?php if ( $show_content ) : ?>
                            <p><?php echo wp_trim_words( get_the_content(), 8, '...' ); ?></p>
                            <?php endif; ?>                        
                        </div><!-- /.text -->                        
                    </li>
                <?php endwhile; ?>
                <?php wp_reset_postdata(); ?>
                <?php else : ?>  
                <?php printf( '<li>%s</li>',esc_html__('Oops, category not found.', 'thmes' )); ?>
            <?php endif; ?>        
            </ul>        
            <?php echo wp_kses_post( $after_widget );
        }
    Kodu kullanacaklar widget setting ayarlarını kendine göre özelleştirebilir