unid_user 63 ارسال شده در بهمن 99 گزارش بازنشر ارسال شده در بهمن 99 (ویرایش شده) سلام و درود دوستان گرامی، چرا زمینه دلخواه با اینکه توی حلقه نوشته شده کار نمیکنه؟ <?php echo get_post_meta($post->ID, 'price', true); ?> همیشه کار کرده ولی الان نه. widgets.php ویرایش شده بهمن 99 توسط unid_user نقل قول لینک به ارسال
unid_user 63 ارسال شده در بهمن 99 مالک گزارش بازنشر ارسال شده در بهمن 99 <?php add_action( 'widgets_init', create_function('', 'return register_widget("hp_recent_posts");') ); class hp_recent_posts extends WP_Widget { public function __construct() { parent::WP_Widget( false, 'دسته بندی های صفحه اصلی',array('description' => __('نمایش آخرین دسته بندی های هر دسته در صفحه اصلی') )); } public function widget( $args, $instance ) { extract( $args ); $headline = $instance['headline']; $category = $instance['category']; $numberposts = $instance['numberposts']; echo $before_widget; $the_query = new WP_Query( array( 'category_name' => $category, 'posts_per_page' => $numberposts ) ); if ( $the_query->have_posts() ) { echo '<section class="mt-5">'; echo $before_title; echo "<h3 class='text-center text-dark sec-title'>$headline</h3>"; echo $after_title; echo '<div class="container"><div class="row">'; $i =0 ; while ( $the_query->have_posts() ) { $the_query->the_post(); $i++; if ($i == 1 ) { echo '<div class="col-lg-6 d-flex align-items-stretch">'; ?> <div class="card mb-2"> <?php the_post_thumbnail('post_thumbnail', ['class' => 'card-img-top']); ?> <div class="card-body"> <h5 class="card-title"><?php the_title(); ?></h5> <a href="<?php the_permalink(); ?>" class="btn btn-success float-start">کد تخفیف</a> <span class="offer-icon"> <?php echo get_post_meta($post->ID, 'offer_percent', true); ?> </span> <span class="text-muted"> | </span> <span class="text-success"><?php echo get_post_meta($post->ID, 'price', true); ?></span> <span class="text-muted"> | </span> <span> <?php echo getPostViews(get_the_ID()); ?> </span> <span class="view-icon"></span> </div> </div> <?php echo '</div>'; } if ($i == 2 ) { echo '<div class="col-lg-6">'; ?> <div class="row"> <div class="col-lg-6"> <div class="card mb-2 ux-card-small"> <?php the_post_thumbnail('post_thumbnail', ['class' => 'card-img-top']); ?> <div class="card-body"> <h5 class="card-title"><?php the_title(); ?></h5> <a href="<?php the_permalink(); ?>" class="btn btn-success float-start">کد تخفیف</a> <span class="offer-icon"> <?php echo get_post_meta($post->ID, 'offer_percent', true); ?> </span> <span class="text-muted"> | </span> <span class="text-success"><?php echo get_post_meta($post->ID, 'price', true); ?></span> <span class="text-muted"> | </span> <span> <?php echo getPostViews(get_the_ID()); ?> </span> <span class="view-icon"></span> </div> </div> </div> <?php } if ($i == 3 ) { ?> <div class="col-lg-6"> <div class="card mb-2 ux-card-small"> <?php the_post_thumbnail('post_thumbnail', ['class' => 'card-img-top']); ?> <div class="card-body"> <h5 class="card-title"><?php the_title(); ?></h5> <a href="<?php the_permalink(); ?>" class="btn btn-success float-start">کد تخفیف</a> <span class="offer-icon"> <?php echo get_post_meta($post->ID, 'offer_percent', true); ?> </span> <span class="text-muted"> | </span> <span class="text-success"><?php echo get_post_meta($post->ID, 'price', true); ?></span> <span class="text-muted"> | </span> <span> <?php echo getPostViews(get_the_ID()); ?> </span> <span class="view-icon"></span> </div> </div> </div> </div> <?php } if ($i == 4 ) { ?> <div class="row"> <div class="col-lg-6"> <div class="card mb-2 ux-card-small"> <?php the_post_thumbnail('post_thumbnail', ['class' => 'card-img-top']); ?> <div class="card-body"> <h5 class="card-title"><?php the_title(); ?></h5> <a href="<?php the_permalink(); ?>" class="btn btn-success float-start">کد تخفیف</a> <span class="offer-icon"> <?php echo get_post_meta($post->ID, 'offer_percent', true); ?> </span> <span class="text-muted"> | </span> <span class="text-success"><?php echo get_post_meta($post->ID, 'price', true); ?></span> <span class="text-muted"> | </span> <span> <?php echo getPostViews(get_the_ID()); ?> </span> <span class="view-icon"></span> </div> </div> </div> <?php } if ($i == 5 ) { ?> <div class="col-lg-6"> <div class="card mb-2 ux-card-small"> <?php the_post_thumbnail('post_thumbnail', ['class' => 'card-img-top']); ?> <div class="card-body"> <h5 class="card-title"><?php the_title(); ?></h5> <a href="<?php the_permalink(); ?>" class="btn btn-success float-start">کد تخفیف</a> <span class="offer-icon"> <?php echo get_post_meta($post->ID, 'offer_percent', true); ?> </span> <span class="text-muted"> | </span> <span class="text-success"><?php echo get_post_meta($post->ID, 'price', true); ?></span> <span class="text-muted"> | </span> <span> <?php echo getPostViews(get_the_ID()); ?> </span> <span class="view-icon"></span> </div> </div> </div> </div> <?php } } echo '</div>'; echo "</div>"; echo "</div>"; echo "</section>"; wp_reset_postdata(); } echo $after_widget; } public function update( $new_instance, $old_instance ) { $instance = array(); $instance['headline'] = ( $new_instance['headline'] ); $instance['category'] = ( $new_instance['category'] ); $instance['numberposts'] = ( $new_instance['numberposts'] ); return $instance; } public function form( $instance ) { $headline = $instance[ 'headline' ]; $category = $instance[ 'category' ]; $numberposts = $instance[ 'numberposts' ]; $categories = get_categories(array('type'=>'post','orderby'=> 'name','order'=> 'ASC')); $defaults = array( 'numberposts' => 3 ); $instance = wp_parse_args( (array) $instance, $defaults ); echo '<p>'; echo '<label for="'. $this->get_field_id( 'headline' ) .'">'. _e( 'عنوان : ' ) .'</label>'; echo '<input class="widefat" id="'. $this->get_field_id( 'headline' ) .'" name="'. $this->get_field_name( 'headline' ) .'" type="text" value="'. esc_attr( $headline ) .'" />'; echo '</p>'; echo '<p>'; echo '<label for="'. $this->get_field_id( 'category' ) .'">'. _e( 'انتخاب دسته بندی : ' ) .'</label>'; echo '<select name="' . $this->get_field_name('category') . '" id="' . $this->get_field_id('category') . '" style="width: 100%;">'; foreach($categories as $category): echo ' <option value="' . $category->slug .'" '. selected($category->slug, $instance['category'], false) . '>' . $category->name . '</option>'; endforeach; echo '</select>'; echo '</p>'; echo '<p>'; echo '<label for="'. $this->get_field_id( 'numberposts' ) .'">'. _e( 'تعداد نوشتههایی که نمایش داده میشود:' ) .'</label>'; echo '<input class="tiny-text" id="'. $this->get_field_id( 'numberposts' ) .'" name="'. $this->get_field_name( 'numberposts' ) .'" type="number" value="'. $instance['numberposts'] .'" step="1" min="1" size="3" />'; echo '</p>'; } } نقل قول لینک به ارسال
asadiy4n 2805 ارسال شده در بهمن 99 گزارش بازنشر ارسال شده در بهمن 99 سلام ایدی و مقدار رو داخل متغیر ذخیر کنین و تست کنید 1 نقل قول لینک به ارسال
unid_user 63 ارسال شده در بهمن 99 مالک گزارش بازنشر ارسال شده در بهمن 99 در 9 دقیقه قبل، asadiy4n گفته است : سلام ایدی و مقدار رو داخل متغیر ذخیر کنین و تست کنید سپاس. درست شد. نقل قول لینک به ارسال
unid_user 63 ارسال شده در مهر 00 مالک گزارش بازنشر ارسال شده در مهر 00 (ویرایش شده) درود این تکه کد تو ورژن جدید وردپرس پشتیبانی نمیشه؟ خطا میده که تابع create_function تعریف نشده. <?php add_action( 'widgets_init', create_function('', 'return register_widget("hp_recent_posts");') ); class hp_recent_posts extends WP_Widget { public function __construct() { parent::WP_Widget( false, 'دسته بندی های صفحه اصلی',array('description' => __('نمایش آخرین دسته بندی های هر دسته در صفحه اصلی') )); } public function widget( $args, $instance ) { extract( $args ); $headline = $instance['headline']; $category = $instance['category']; $numberposts = $instance['numberposts']; echo $before_widget; $category_id = get_cat_ID($category); $category_url = get_category_link($category_id); echo '<a href="'.$category_url.'">'.$category.'</a>'; $the_query = new WP_Query( array( 'category_name' => $category, 'posts_per_page' => $numberposts ) ); if ( $the_query->have_posts() ) { $i =0 ; while ( $the_query->have_posts() ) { $the_query->the_post(); $i++; //echo $ads_price; if ($i == 1 ) { } if ($i == 2 ) { } if ($i == 3 ) { } if ($i == 4 ) { } if ($i == 5 ) { } } wp_reset_postdata(); } echo $after_widget; } public function update( $new_instance, $old_instance ) { $instance = array(); $instance['headline'] = ( $new_instance['headline'] ); $instance['category'] = ( $new_instance['category'] ); $instance['numberposts'] = ( $new_instance['numberposts'] ); return $instance; } public function form( $instance ) { $headline = $instance[ 'headline' ]; $category = $instance[ 'category' ]; $numberposts = $instance[ 'numberposts' ]; $categories = get_categories(array('type'=>'post','orderby'=> 'name','order'=> 'ASC')); $defaults = array( 'numberposts' => 3 ); $instance = wp_parse_args( (array) $instance, $defaults ); echo '<p>'; echo '<label for="'. $this->get_field_id( 'headline' ) .'">'. _e( 'عنوان : ' ) .'</label>'; echo '<input class="widefat" id="'. $this->get_field_id( 'headline' ) .'" name="'. $this->get_field_name( 'headline' ) .'" type="text" value="'. esc_attr( $headline ) .'" />'; echo '</p>'; echo '<p>'; echo '<label for="'. $this->get_field_id( 'category' ) .'">'. _e( 'انتخاب دسته بندی : ' ) .'</label>'; echo '<select name="' . $this->get_field_name('category') . '" id="' . $this->get_field_id('category') . '" style="width: 100%;">'; foreach($categories as $category): echo ' <option value="' . $category->name .'" '. selected($category->name, $instance['category'], false) . '>' . $category->name . '</option>'; endforeach; echo '</select>'; echo '</p>'; echo '<p>'; echo '<label for="'. $this->get_field_id( 'numberposts' ) .'">'. _e( 'تعداد نوشتههایی که نمایش داده میشود:' ) .'</label>'; echo '<input class="tiny-text" id="'. $this->get_field_id( 'numberposts' ) .'" name="'. $this->get_field_name( 'numberposts' ) .'" type="number" value="'. $instance['numberposts'] .'" step="1" min="1" size="3" />'; echo '</p>'; } } ویرایش شده مهر 00 توسط unid_user نقل قول لینک به ارسال
پست های پیشنهاد شده
به گفتگو بپیوندید
هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .