自定义Wordpress插件问题与打印结果

时间:2018-11-14 06:41:13

标签: php wordpress

我创建了一个Wordpress插件,问题是,我正在根据类别打印帖子。

我想要这样的结果:

category 1
-------
post of category 1
second post of category 1

category 2
-------
post of category 2
second post of category 2

但是我得到的结果是这样的:

post of category 1second post of category 1post of category 2second post of category 2
category 1
-------

category 2
-------

帖子正在类别框外打印。

这是我的代码:

function show_opicle_cat()
{
    //database query
    $cats = get_categories($args); 

    // loop through the categries
    foreach ($cats as $cat) {
        // setup the cateogory ID
        $cat_id= $cat->term_id;

       // Make a header for the cateogry
       $pos .= "<div class='col-md-12' style='margin-bottom:2%;display:inherit !important;padding:0 !important;' ><div style='border:1px solid #cfcfcf !important;'>";
       $pos .= "<h6 style='background:#3b8b98!important;color:#fff;padding:10px;'>".ucwords($cat->name)." <a href='".get_category_link( $cat_id )."' class='pull-right' style='color:#fff !important;padding:0px 3px;bertical-align:middle;border:2px solid #fff;'>View All</a></h6><ul style='list-style-type:disc !important;'>";
       // create a custom wordpress query
       query_posts("cat=$cat_id&posts_per_page=$posts");
       // start the wordpress loop!
       if (have_posts()) : while (have_posts()) : the_post(); 
           // create our link now that the post is setup 
           $pos .="<li><img class='alignnone size-full wp-image-10424' src='newicon.gif' alt='' width='30' height='14'><a href='hii'>&nbsp;".ucwords(the_title())."</a></li>";
       endwhile; endif; // done our wordpress loop. Will start again for each category 
       $pos .="</ul></div></div>"; 
   } // done the foreach statement 
   return $pos;
}

0 个答案:

没有答案