最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - wordpress custom category post shortcode

programmeradmin3浏览0评论

Does not work this code...

function category_post_shortcode($atts){
        extract(shortcode_atts(array(
          'title' => '',
          'link'  => '',
          'category' => '',
        ), $atts, 'category_post' ) );

        $q = new WP_Query(
          array( 'category' => $category, 'posts_per_page' => '3', 'post_type' => 'post')
        );

        $list = '<div class="latest_form_category"><h2 class="latest_form_category_title">'.$title.'</h2><a href="'.$link.'" class="latest_more_link">More</a>';

        while($q->have_posts()) : $q->the_post();
        $id = get_the_ID();
109 no line =>    $post_excerpt = get_post_meta($id, 'post_excerpt', true);
        $post_thumbnail = get_the_post_thumbnail( $post->ID, 'post-thumbnail');
        $list .= '
                  <div class="single_cat_post floatleft">
                    '.$post_thumbnail.'
                    <h3>'.get_the_title().'</h3>
                    <p>'.$post_excerpt.'</p>
                    <a href="'.get_permalink().'" class="readmore">Read More</a>
                  </div>

          ';
        endwhile;
        $list .= '</div>';
        wp_reset_query();
        return $list;
}
add_shortcode( 'category_post', 'category_post_shortcode' );

发布评论

评论列表(0)

  1. 暂无评论