Rohani 389 ارسال شده در آبان 92 گزارش بازنشر ارسال شده در آبان 92 سلام دوستان آیا برای استفاده از دستورات کوئری میشه آنها رو در ابزارک متن استفاده کرد؟نکته: افزونه پشتیبانی php رو در ابزارک فعال کردم.یا اینکه باید یک سایدار استاتیک تعریف کنم؟بهترینش کدوم کاره؟ نقل قول لینک به ارسال
imanfakhar 26231 ارسال شده در آبان 92 گزارش بازنشر ارسال شده در آبان 92 بهترینش ساخت یک ابزارک دلخواهه class MyNewWidget extends WP_Widget {function MyNewWidget() { // مشخصات پنلی که درز صفحه ابزارک ها می بینید parent::__construct( false, 'My New Widget Title' );}function widget( $args, $instance ) { // کد خروجی مورد نظر}function update( $new_instance, $old_instance ) { // گزینه های متغیر ابزارک برای ذخیره سازی}function form( $instance ) { //خروجی فرم}}function myplugin_register_widgets() {register_widget( 'MyNewWidget' );}add_action( 'widgets_init', 'myplugin_register_widgets' );نمونه عملی add_action( 'widgets_init', 'my_widget' );function my_widget() {register_widget( 'MY_Widget' );}class MY_Widget extends WP_Widget {function MY_Widget() { $widget_ops = array( 'classname' => 'example', 'description' => __('A widget that displays the authors name ', 'example') ); $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'example-widget' ); $this->WP_Widget( 'example-widget', __('Example Widget', 'example'), $widget_ops, $control_ops );}function widget( $args, $instance ) { extract( $args ); //Our variables from the widget settings. $title = apply_filters('widget_title', $instance['title'] ); $name = $instance['name']; $show_info = isset( $instance['show_info'] ) ? $instance['show_info'] : false; echo $before_widget; // Display the widget title if ( $title ) echo $before_title . $title . $after_title; //Display the name if ( $name ) printf( '<p>' . __('Hey their Sailor! My name is %1$s.', 'example') . '</p>', $name ); if ( $show_info ) printf( $name ); echo $after_widget;}//Update the widgetfunction update( $new_instance, $old_instance ) { $instance = $old_instance; //Strip tags from title and name to remove HTML $instance['title'] = strip_tags( $new_instance['title'] ); $instance['name'] = strip_tags( $new_instance['name'] ); $instance['show_info'] = $new_instance['show_info']; return $instance;}function form( $instance ) { //Set up some default widget settings. $defaults = array( 'title' => __('Example', 'example'), 'name' => __('Bilal Shaheen', 'example'), 'show_info' => true ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> //Widget Title: Text Input. <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'example'); ?></label> <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" /> </p> //Text Input. <p> <label for="<?php echo $this->get_field_id( 'name' ); ?>"><?php _e('Your Name:', 'example'); ?></label> <input id="<?php echo $this->get_field_id( 'name' ); ?>" name="<?php echo $this->get_field_name( 'name' ); ?>" value="<?php echo $instance['name']; ?>" style="width:100%;" /> </p> //Checkbox. <p> <input class="checkbox" type="checkbox" <?php checked( $instance['show_info'], true ); ?> id="<?php echo $this->get_field_id( 'show_info' ); ?>" name="<?php echo $this->get_field_name( 'show_info' ); ?>" /> <label for="<?php echo $this->get_field_id( 'show_info' ); ?>"><?php _e('Display info publicly?', 'example'); ?></label> </p><?php} } 6 نقل قول لینک به ارسال
Rohani 389 ارسال شده در آبان 92 مالک گزارش بازنشر ارسال شده در آبان 92 ممنون دوست عزیز روش جالبی است.آیا لینک آموزشی کامل تری موجود هست؟ 1 نقل قول لینک به ارسال
Parsa 23463 ارسال شده در آبان 92 گزارش بازنشر ارسال شده در آبان 92 چند آموزش:http://colorlabsproject.com/tutorials/how-to-create-a-simple-widget-on-wordpress/http://wp.tutsplus.com/tutorials/creative-coding/building-custom-wordpress-widgets/http://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-wordpress-widget/ 3 نقل قول لینک به ارسال
Rohani 389 ارسال شده در آبان 92 مالک گزارش بازنشر ارسال شده در آبان 92 من از کد زیر استفاده کردم ابزارک ساخته شد.// Creating the widgetclass wpb_widget extends WP_Widget {function __construct() {parent::__construct(// Base ID of your widget'wpb_widget',// Widget name will appear in UI__('WPBeginner Widget', 'wpb_widget_domain'),// Widget descriptionarray( 'description' => __( 'Sample widget based on WPBeginner Tutorial', 'wpb_widget_domain' ), ));}// Creating widget front-end// This is where the action happenspublic function widget( $args, $instance ) {$title = apply_filters( 'widget_title', $instance['title'] );// before and after widget arguments are defined by themesecho $args['before_widget'];if ( ! empty( $title ) )echo $args['before_title'] . $title . $args['after_title'];// This is where you run the code and display the outputecho __( 'Hello, World!', 'wpb_widget_domain' );echo $args['after_widget'];}// Widget Backendpublic function form( $instance ) {if ( isset( $instance[ 'title' ] ) ) {$title = $instance[ 'title' ];}else {$title = __( 'New title', 'wpb_widget_domain' );}// Widget admin form?><p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></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 esc_attr( $title ); ?>" /></p><?php}// Updating widget replacing old instances with newpublic function update( $new_instance, $old_instance ) {$instance = array();$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';return $instance;}} // Class wpb_widget ends here// Register and load the widgetfunction wpb_load_widget() {register_widget( 'wpb_widget' );}add_action( 'widgets_init', 'wpb_load_widget' );اما دستورات کوئری را باید کجای ای کد قرار بدم؟ نقل قول لینک به ارسال
imanfakhar 26231 ارسال شده در آبان 92 گزارش بازنشر ارسال شده در آبان 92 بجای echo __( 'Hello, World!', 'wpb_widget_domain' ); 3 نقل قول لینک به ارسال
Rohani 389 ارسال شده در آبان 92 مالک گزارش بازنشر ارسال شده در آبان 92 به کلمه <?php گیر میده!کدی که گذاشتم:به خط اول گیر میده!<?php $custom_query = new WP_Query(array('post_status' =>'publish','post_type' =>'post','order' =>'descending','orderby' =>'ID','cat' =>'3','posts_per_page' =>'5', 'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1 )); ?><?php if($custom_query->have_posts()) :while($custom_query->have_posts()) : $custom_query->the_post();?><?php the_title(); ?><?php endwhile;endif;?><?php wp_reset_query(); ?> نقل قول لینک به ارسال
عبدالماجد 3203 ارسال شده در آبان 92 گزارش بازنشر ارسال شده در آبان 92 چون قبل از این کدها تگ پی اچ پی باز شده و هنوز بسته نشده گیر میده.تمامی تگهای باز و بسته شدن php رو از این قسمت از کدهاتون که توی عکس مشخصه بردارید.اینها منظورمه :<?php و?> 4 نقل قول لینک به ارسال
Rohani 389 ارسال شده در آبان 92 مالک گزارش بازنشر ارسال شده در آبان 92 (ویرایش شده) میشه بگید کدوما رو بردارم.؟هر کدوم رو برمیدارم یا کار نمیکنه یا باز خطا میده!<?php// Creating the widgetclass wpb_widget extends WP_Widget {function __construct() {parent::__construct(// Base ID of your widget'wpb_widget',// Widget name will appear in UI__('WPBeginner Widget', 'wpb_widget_domain'),// Widget descriptionarray( 'description' => __( 'Sample widget based on WPBeginner Tutorial', 'wpb_widget_domain' ), ));}// Creating widget front-end// This is where the action happenspublic function widget( $args, $instance ) {$title = apply_filters( 'widget_title', $instance['title'] );// before and after widget arguments are defined by themesecho $args['before_widget'];if ( ! empty( $title ) )echo $args['before_title'] . $title . $args['after_title'];// This is where you run the code and display the output<?php$custom_query = new WP_Query(array('post_status' =>'published','post_type' =>'post','order' =>'descending','orderby' =>'ID','cat' =>'61','posts_per_page' =>'5','paged' => (get_query_var('paged')) ? get_query_var('paged') : 1));?><ul><?php if($custom_query->have_posts()) :while($custom_query->have_posts()) : $custom_query->the_post();?><li><strong><?php the_title(); ?></strong> <a class="links" href="<?php the_permalink(); ?>"> پیوند یکتا</a><div class="post" id="post<?php echo the_ID();?>"> <?php the_content(); ?></div></li><?php endwhile;endif;?></ul><?php wp_reset_query(); ?>echo $args['after_widget'];}// Widget Backendpublic function form( $instance ) {if ( isset( $instance[ 'title' ] ) ) {$title = $instance[ 'title' ];}else {$title = __( 'New title', 'wpb_widget_domain' );}// Widget admin form?><p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></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 esc_attr( $title ); ?>" /></p><?php}// Updating widget replacing old instances with newpublic function update( $new_instance, $old_instance ) {$instance = array();$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';return $instance;}} // Class wpb_widget ends here// Register and load the widgetfunction wpb_load_widget() {register_widget( 'wpb_widget' );}add_action( 'widgets_init', 'wpb_load_widget' );?> ویرایش شده آبان 92 توسط نـایس تم نقل قول لینک به ارسال
Rohani 389 ارسال شده در آبان 92 مالک گزارش بازنشر ارسال شده در آبان 92 کد زیر رو هم باید به شکل زیر قرار بدم؟<?php the_title(); ?>php the_title(); نقل قول لینک به ارسال
Morteza 34190 ارسال شده در آبان 92 گزارش بازنشر ارسال شده در آبان 92 تست کنید <?php// Creating the widgetclass wpb_widget extends WP_Widget {function __construct() {parent::__construct(// Base ID of your widget'wpb_widget',// Widget name will appear in UI__('WPBeginner Widget', 'wpb_widget_domain'),// Widget descriptionarray( 'description' => __( 'Sample widget based on WPBeginner Tutorial', 'wpb_widget_domain' ), ));}// Creating widget front-end// This is where the action happenspublic function widget( $args, $instance ) {$title = apply_filters( 'widget_title', $instance['title'] );// before and after widget arguments are defined by themesecho $args['before_widget'];if ( ! empty( $title ) )echo $args['before_title'] . $title . $args['after_title'];// This is where you run the code and display the output$custom_query = new WP_Query(array('post_status' =>'published','post_type' =>'post','order' =>'descending','orderby' =>'ID','cat' =>'61','posts_per_page' =>'5','paged' => (get_query_var('paged')) ? get_query_var('paged') : 1));?><ul><?php if($custom_query->have_posts()) :while($custom_query->have_posts()) : $custom_query->the_post();?><li><strong><?php the_title(); ?></strong> <a class="links" href="<?php the_permalink(); ?>"> پیوند یکتا</a><div class="post" id="post<?php echo the_ID();?>"> <?php the_content(); ?></div></li><?php endwhile;endif;?></ul><?php wp_reset_query();echo $args['after_widget'];}// Widget Backendpublic function form( $instance ) {if ( isset( $instance[ 'title' ] ) ) {$title = $instance[ 'title' ];}else {$title = __( 'New title', 'wpb_widget_domain' );}// Widget admin form?><p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></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 esc_attr( $title ); ?>" /></p><?php}// Updating widget replacing old instances with newpublic function update( $new_instance, $old_instance ) {$instance = array();$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';return $instance;}} // Class wpb_widget ends here// Register and load the widgetfunction wpb_load_widget() {register_widget( 'wpb_widget' );}add_action( 'widgets_init', 'wpb_load_widget' );?> 3 نقل قول لینک به ارسال
Parsa 23463 ارسال شده در آبان 92 گزارش بازنشر ارسال شده در آبان 92 این دو خط رو حذف کنید// This is where you run the code and display the output<?php 2 نقل قول لینک به ارسال
Rohani 389 ارسال شده در آبان 92 مالک گزارش بازنشر ارسال شده در آبان 92 آقا نشد که نشد! نقل قول لینک به ارسال
Parsa 23463 ارسال شده در آبان 92 گزارش بازنشر ارسال شده در آبان 92 کد مرتضی که خطا نداره 2 نقل قول لینک به ارسال
Rohani 389 ارسال شده در آبان 92 مالک گزارش بازنشر ارسال شده در آبان 92 ممنون از همتون به خصوص آقا مرتضی درست شد مشکل از من بود. تو کد زیر آیدی 61 موجود نبود.'cat' =>'61',موندم چه جوری تشکر کنم به این خوبی و سرعت زیاد وقت میذارید و جواب میدید.مرسی. نقل قول لینک به ارسال
پست های پیشنهاد شده
به گفتگو بپیوندید
هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .