2017-02-19 26 views
0

我想添加一個特定的短代碼到我的主題中,但是當我將下面的代碼粘貼到我的主題function.php中時出現錯誤。我已經在function.php中嘗試過including once,但沒有奏效。wordpress 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'); 
+0

你得到的錯誤是什麼? – Shawn

+0

清除問題中的噪音。請考慮清理您的代碼縮進以使其更易於閱讀。 – Shawn

回答

0

右上角有一個語法錯誤 - 您的PHP標籤有問題。您需要在HTML之前關閉php標籤,並在之後打開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'); 

不保證該是你所有的問題,但這是你提供的代碼示例中的一個關鍵問題。

+0

你好,非常感謝,如果沒有你,我將無法做到這一點,我想知道你是如何看到這些的,而我卻沒有。 –

+0

你打賭@johnpink!我教授編碼,並且有許多練習掃描語法錯誤 - 總是看看HMTL,因爲很容易忘記這些標籤。本網站的典型做法是「接受」答案,如果它對你有幫助。你也可以看看有錯誤檢查的編碼環境 - 有很多可用的。 – magi182

相關問題