0

Всем привет. Для сайта Wordpress создал файл виджета со слайдером. Виджет вставляется на страницу, которая затем будет главной страницей сайта. Сайт грузится, но страница с этим виджетом нет. Дебаггер молчит, страница долго грузится потом браузер выдает "опаньки") JS-Плагин слайдера отключать пробовал, не помогает. Наверное намудрил с циклами. Помогите, кто чем может

<?php
/* 
Plugin Name: Post Slider 
*/    
add_action( 'widgets_init', 'front_slider_widget' );

function front_slider_widget() {register_widget( 'front_slider_zm' );}

class front_slider_zm extends WP_Widget {

    /* Register widget with WordPress. */

    function __construct() {
        parent::__construct(
                'front_slider_widget_zm',   //Widget ID
                __('Front Slider', 'zanuda'), // Name
                array( 'description' => '', ) // Args
        );}

        /* Front-end display of widget. */

        public function widget( $args, $instance ) {

            $defaults = array( 'title' => 'Front Slider', 'number' => 7, 'widget_size' => 'three-post-slider', 'categories' => 'all', 'author' => 'on', 'date' => 'on', 'cat_show' => 'on');
            $instance = wp_parse_args( (array) $instance, $defaults );

            $number = $instance['number'];
            $categories = $instance['categories'];
            $widget_size = $instance['widget_size'];
            $author = $instance['author'];
            $date = $instance['date'];
            $cat_show = $instance['cat_show'];

            $args['before_widget'] = str_replace('class="home-content', 'class="home-content '. esc_attr($widget_size) , $args['before_widget']);       
                echo $args['before_widget'];
                if ( ! empty( $title ) ){
                    echo $args['before_title'];     
                        if($categories != 0){echo '<a href='.esc_url(get_category_link( $categories )).'>';}        
                    echo esc_html($title);          
                        if($categories != 0){echo '</a>';}
                    echo $args['after_title'];}
            ?>

<div class="front-slider">

    <div class="front-slider-shift"> 

        <?php $zm_posts = new WP_Query(array( 
                'cat' => $categories,
                'posts_per_page' =>  ($number * 1)
                )); 
            while($zm_posts->have_posts()) { $zm_posts->the_post(); ?>

        <div class="front-slider-part">

            <div class="front-slider-banner">

                <div class="slide-image post-image" style="background-image: url(<?php echo get_the_post_thumbnail_url(array() );?>);"></div>

                    <div class="post-slider-text-box">
                    <?php if($cat_show) { ?>
                    <div class="entry-category" itemprop="articleSection">
                        <?php $category = get_the_category(); if($category[0]){echo '<a href="'.esc_url(get_category_link($category[0]->term_id )).'" title="'.esc_attr($category[0]->cat_name).'">'.esc_html($category[0]->cat_name).'</a>';} ?>
                    </div>
                    <!--post-slider-category-->
                    <?php } ?>

                    <div class="post-slider-title">
                        <h2 itemprop="headline">
                            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                                <?php the_title(); ?>
                            </a>
                        </h2>
                    </div>
                    <!--post-slide-title-->

                    <?php if($author || $date ) { ?>
                        <div class="entry-meta">
                            <?php if($author) { ?>
                            <div class="author" itemprop="author">
                                <?php echo get_the_author(); ?>
                            </div>
                            <!--author-->
                            <?php } ?>
                            <?php if($date) { ?>
                            <div class="date" itemprop="datePublished" content="<?php the_time( 'c' ); ?>">
                                <?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' назад';  ?>
                            </div>
                            <!--date-->
                            <?php } ?>
                        </div>
                        <!--author-date-->
                        <?php } ?>
                </div>
                <!--post-slider-text-box--> 

                <div class="blog-post-content" itemprop="description" content="<?php $excerpt = get_the_excerpt(); echo $excerpt;?>">
                    <?php the_excerpt(); ?>
                </div>  
            </div>
        </div>
                        <?php }?>
    </div>

    <div class="front-slider-change">

        <?php while($zm_posts->have_posts()) { $zm_posts->the_post();?>

            <div class="item">
                                    <div class="banner-carousel-item">

                                        <h5>
                                            <?php the_title()?>
                                        </h5> 
                                    </div>
            </div>
                                <?php } ?>
    </div>                 

</div>

<?php wp_reset_postdata();?>

<?php   
    /* After widget. */ 

        echo $args['after_widget'];
    }

    /* Widget settings. */

    function update( $new_instance, $old_instance ) {
        $instance = $old_instance;  

        /* Strip tags. */

        $instance['number'] = $new_instance['number'];
        $instance['categories'] = $new_instance['categories'];
        $instance['widget_size'] = $new_instance['widget_size'];
        $instance['author'] = $new_instance['author'];
        $instance['date'] = $new_instance['date'];  
        $instance['cat_show'] = $new_instance['cat_show'];

        return $instance;
    }       

        /* Default widget settings. */

    function form( $instance ) {    
        $defaults = array( 'title' => 'Post Slider', 'number' => 7, 'widget_size' => 'three-post-slider', 'categories' => 'all', 'author' => 'on', 'date' => 'on', 'cat_show' => 'on');
        $instance = wp_parse_args( (array) $instance, $defaults ); ?>

<!-- Width -->
<p>
    <label for="<?php echo esc_attr($this->get_field_id('widget_size')); ?>"><?php _e('Размер слайдера:', 'plumbum');?></label>
    <select name="<?php echo esc_attr($this->get_field_name('widget_size')); ?>" id="<?php echo esc_attr($this->get_field_id('widget_size')); ?>" class="widefat" >
        <?php $options = array('three-post-slider', 'one-post-slider');
        foreach ($options as $option) {?>
        <option value='<?php echo esc_attr($option); ?>' <?php if ($option == $instance['widget_size']) echo 'selected="selected"'; ?>><?php echo esc_html($option); ?></option>
        <?php } ?>
    </select>
</p>

<!-- Number of posts -->
<p>
    <label for="<?php echo esc_attr($this->get_field_id( 'number' )); ?>">
        <?php _e('Количество слайдов', 'plumbum'); ?>
    </label>
    <input type="number" min="1" id="<?php echo esc_attr($this->get_field_id( 'number' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'number' )); ?>" value="<?php echo esc_attr($instance['number']); ?>" size="3" />
</p>

<!-- Category -->
<p>
    <label for="<?php echo esc_attr($this->get_field_id('categories')); ?>">
        <?php _e('Выбрать рубрику', 'plumbum'); ?>
    </label>
    <select id="<?php echo esc_attr($this->get_field_id('categories')); ?>" name="<?php echo esc_attr($this->get_field_name('categories')); ?>" style="width:100%;">
        <option value='all' <?php if ('all' == (isset($instance['categories']))) echo 'selected="selected"'; ?>>
        <?php _e('Все рубрики', 'plumbum'); ?>
        </option>
        <?php $categories = get_categories('hide_empty=0&depth=1&type=post'); ?>
        <?php foreach($categories as $category) { ?>
        <option value='<?php echo esc_attr($category->term_id); ?>' <?php if(isset($instance['categories'])){ if ($category->term_id == $instance['categories']) echo 'selected="selected"';}?>>
        <?php echo esc_html($category->cat_name); ?>
        </option>
        <?php } ?>
    </select>
</p>

<!-- Author -->
<p>
    <label for="<?php echo esc_attr($this->get_field_id( 'author' )); ?>">
        <?php _e('Показать автора:', 'plumbum'); ?>
    </label>
    <input type="checkbox" id="<?php echo esc_attr($this->get_field_id( 'author' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'author' )); ?>" <?php checked( (bool) $instance['author'], true ); ?> />
</p>
<!-- Date -->
<p>
    <label for="<?php echo esc_attr($this->get_field_id( 'date' )); ?>">
        <?php _e('Показать дату:', 'plumbum'); ?>
    </label>
    <input type="checkbox" id="<?php echo esc_attr($this->get_field_id( 'date' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'date' )); ?>" <?php checked( (bool) $instance['date'], true ); ?> />
</p>
<!-- category show -->
<p>
    <label for="<?php echo esc_attr($this->get_field_id( 'cat_show' )); ?>">
        <?php _e('Показать рубрику:', 'plumbum'); ?>
    </label>
    <input type="checkbox" id="<?php echo esc_attr($this->get_field_id( 'cat_show' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'cat_show' )); ?>" <?php checked( (bool) $instance['cat_show'], true ); ?> />
</p>

<?php }} ?>
1
  • убрал все циклы - проблема осталась...может что в самом коде виджета...интересно, что до этого работало все 16 сен 2019 в 14:26

1 ответ 1

1

Нашел ответ. Все таки проблема была в слайдере.

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.