wordpress短代码只显示其名称

时间:2015-09-15 10:09:33

标签: wordpress

<?php
    function ash_now_big(){
        $debut = 0; //The first article to be displayed
        query_posts('cat=45&showposts=1');
        while(have_posts()) : the_post();//while loop
            $myposts = get_posts('numberposts=-1&offset=$debut');
            if (has_post_thumbnail( $post->ID ) ): 
                $output .= $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); 
                $output .=' <a href="'. the_permalink().'"><img src="'. $image[0] .'" style="width:100%"></a>';
          endif; // end of if
      endwhile; //end of while
 return $output;
}   
add_shortcode("ash_now_big", "ash_now_big");//creating shortcode

这个短代码在使用时只显示[ash_now_big]可能是什么问题

1 个答案:

答案 0 :(得分:1)

您将此代码放在项目中的哪个位置?你有插件还是只想把它放在功能文件中?

请将以下代码放在主题functions.php文件中:

function ash_now_big(){
        $debut = 0; //The first article to be displayed
        query_posts('cat=1&showposts=1');
        while(have_posts()) : the_post();//while loop
            $myposts = get_posts('numberposts=-1&offset=$debut');
            if (has_post_thumbnail( $post->ID ) ): 
                $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); 
                $output .=' <a href="'. get_the_permalink().'"><img src="'. $image[0] .'" style="width:100%"></a>';
            endif; // end of if
        endwhile; //end of while
    return $output;
}   
add_shortcode("ash_now_big", "ash_now_big");//creating shortcode