רוצים את הטופס והתגובות בתפריט צד?

תיאור:

הסניפט הבא די מורכב כיוון שהוא דורש ידע בCSS כדי ליצור מראה סביר והבנה של PHP כדי לעשות שינויים אבל אם אתם רוצים מאיזושהי סיבה להציג את הטופס של התגובות והתגובות עצמן בסרגל צד הנה וידג'ט שעושה את זה בשבילכם לאחר שתמקמו את הסניפט הבא בקובץ functions.php.

first קוד:

  • מה: סניפט שיוצר וידג'ט תגובות שיופיע רק בפוסטים
  • איפה: בקובץ Functions.php
<?php
class commentsCustomWidget extends WP_Widget {
    function commentsCustomWidget() {
        $widget_ops = array('classname' => 'custom_comments_widget', 'description' => __( 'a widget that displays comments and commentform', 'your_textdomain') );
        $this->WP_Widget('custom-comment-widget', __('WPE Comments', 'your_textdomain'), $widget_ops);
    }
    function widget($args, $instance) {
        if(is_single()) {
            extract($args);
            global $post;
            echo $before_widget;
            comments_template();
            echo $after_widget;
        }
    }
    function update($new_instance, $old_instance) {
        $instance = $old_instance;
        return $instance;
    }
    function form($instance) {
        ?>
        <p><?php _e('This widget will be displayed only in posts.', 'your_textdomain'); ?></p>
       <?php
    }
}
register_widget('commentsCustomWidget');
?>

סניפטים דומים: