Ошибка в файле wordpress function.php

Я пытаюсь добавить определенный шорткод в свою тему, но получаю сообщение об ошибке, когда вставляю приведенный ниже код в свои темы function.php. Я уже пробовал including once в function.php, но это не сработало.

Я думаю, проблема в префиксе <?php и суффиксе ?>, которые запрещены в wordpress fucntion.php. Я удалил все <?php и ?>, но все равно выдает ошибку.

// Add Shortcode
function acardio_big_grid_1() {

  <div class="col-md-12 featt big-grid">
    <div class="container-fluid no-padding">

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array('post_type' => 'post', 'posts_per_page' => 5, 'paged' => $paged);
    $query = new WP_Query($args);
    if( $query->have_posts() ) :
    while( $query->have_posts() ) : $query->the_post(); ?>
<?php $count++; ?>
<?php if ($count == 1) : ?>




                <div class="big-pane col-xs-6">
                <div class="the-big-pane image">
                <div class="img-responsive"> <?php if ( has_post_thumbnail() ) : ?>
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('big-grid-one-image'); ?></a>
    <?php else : ?>
        <img src="



<?php if (function_exists('get_option_tree') ) : if (get_option_tree('defualt_fatured_uploader')) :  ?>

        <?php get_option_tree( 'defualt_fatured_uploader', '', 'true' ); ?>
        <?php else : ?>

        <?php echo get_template_directory_uri (); ?>/img/nothumb-featured.png

    <?php endif; endif; ?>


        " />


    <?php endif; ?></div>
                </div>
                <div class="big-pane overlay">

                  <div class="the-big-pane-content">
                   <div class="the-cont-cat">
   <span class="the-content-cat-bt">  <?php $category = get_the_category(); if ($category) 
                    { echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');}  ?></span>  <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
  </div>
                    <h1><a href="<?php the_permalink(); ?>"><?php echo wp_trim_words( get_the_title(), 15 ); ?></a></h1>
                    <span class="the-content-post-data"><span class="the-auth-post-image-content" style="padding-top: 0px !important;"> <?php echo get_avatar( get_the_author_meta( 'user_email' ), 100 ); ?> </span> By <a href="#"><?php the_author_posts_link(); ?></a> <span class="the-content-post-date"> <i class="fa fa-clock-o the-content "></i><?php the_time('jS M, Y') ?></span> </span>
                  </div>
                </div>
                </div>


                <?php elseif ($count == 2) : ?>  
                <div class="small-pane-holder1 col-xs-6">
                <div class="small-pane col-xs-6 one">
                <div class="the-small-pane-image">
                <?php the_post_thumbnail();?>
                </div>
                  <div class="small-pane-overlay">
                    <div class="small-pan-content">
                     <div class="the-cont-cat">
   <span class="the-content-cat-bt">  <?php $category = get_the_category(); if ($category) 
                    { echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');}  ?></span>  <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
  </div>
  <h1 class="small-pane-title"><a href="<?php the_permalink(); ?>"><?php echo wp_trim_words( get_the_title(), 10 ); ?></a></h1>

                    </div>
                  </div>
                </div>

                <?php elseif ($count == 3) : ?>
                <div class="small-pane col-xs-6 two">
                <div class="the-small-pane-image">
                <?php the_post_thumbnail();?>
                </div>
                  <div class="small-pane-overlay">
                    <div class="small-pan-content">
                     <div class="the-cont-cat">
   <span class="the-content-cat-bt">  <?php $category = get_the_category(); if ($category) 
                    { echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');}  ?></span>  <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
  </div>
  <h1 class="small-pane-title"><a href="<?php the_permalink(); ?>"><?php echo wp_trim_words( get_the_title(), 10 ); ?></a></h1>

                    </div>
                  </div>
                </div>

                <?php elseif ($count == 4) : ?> 
                <div class="small-pane col-xs-6 three">
                <div class="the-small-pane-image">
                <?php the_post_thumbnail();?>
                </div>
                  <div class="small-pane-overlay">
                    <div class="small-pan-content">
                     <div class="the-cont-cat">
   <span class="the-content-cat-bt">  <?php $category = get_the_category(); if ($category) 
                    { echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');}  ?></span>  <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
  </div>
  <h1 class="small-pane-title"><a href="<?php the_permalink(); ?>"><?php echo wp_trim_words( get_the_title(), 10 ); ?></a></h1>

                    </div>
                  </div>
                </div>

                <?php elseif ($count == 5) : ?> 
                <div class="small-pane col-xs-6 four">
                <div class="the-small-pane-image">
                <?php the_post_thumbnail();?>
                </div>
                  <div class="small-pane-overlay">
                    <div class="small-pan-content">
                     <div class="the-cont-cat">
   <span class="the-content-cat-bt">  <?php $category = get_the_category(); if ($category) 
                    { echo wp_kses_post('<a href="' . get_category_link( $category[0]->term_id ) . '" class="tiptipBlog" title="' . sprintf( esc_html__( "View all posts in %s", "acardio" ), $category[0]->name ) . '" ' . '>' . $category[0]->name.'</a> ');}  ?></span>  <span class="the-content-cat-bt"> <?php taqyeem_get_score(); ?> </span>
  </div>
  <h1 class="small-pane-title"><a href="<?php the_permalink(); ?>"><?php echo wp_trim_words( get_the_title(), 10 ); ?></a></h1>

                    </div>
                  </div>
                </div>

    </div>  



<?php else : ?>

  <?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>

</div>
</div>
}
add_shortcode( 'acardio-big-grid-1', 'acardio_big_grid_1' );

person john pink    schedule 19.02.2017    source источник
comment
Какую ошибку вы получаете?   -  person Shawn    schedule 20.02.2017
comment
Убран шум в вопросе. Пожалуйста, подумайте об очистке отступов в коде, чтобы его было легче читать.   -  person Shawn    schedule 20.02.2017


Ответы (1)


В самом верху у вас есть синтаксическая ошибка - проблема с вашими тегами PHP. Вам нужен закрывающий тег php перед HTML и открывающий тег PHP после. Верхняя часть кода должна выглядеть так:

function acardio_big_grid_1() {

?>
  <div class="col-md-12 featt big-grid">
    <div class="container-fluid no-padding">

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('post_type' => 'post', 'posts_per_page' => 5, 'paged' => $paged);

У вас есть аналогичная проблема в конце примера кода, но на этот раз отсутствует открывающий тег php:

<?php endwhile; ?>
<?php endif; ?>

</div>
</div>

<?php
    }
add_shortcode( 'acardio-big-grid-1', 'acardio_big_grid_1' );

Нет гарантий, что это все ваши проблемы, но это будет одна из ключевых проблем в приведенном вами примере кода.

person magi182    schedule 19.02.2017
comment
привет, большое спасибо, я бы не смог сделать это без вас, мне интересно, как вы их видели, а я нет. - person john pink; 19.02.2017
comment
Спорим, @johnpink! Я преподаю кодирование и много практикуюсь в поиске синтаксических ошибок — всегда ищите HMTL, потому что эти теги легко забыть. Типичная практика на этом сайте — принять ответ, если он вам помог. Вы также можете проверить среды кодирования с проверкой ошибок — их много. - person magi182; 20.02.2017