wordpress中有很多有很用的函数,如果再结合一些php其它去扩展,真的可以实现各种各样的变态的请求。比如下面的这段代码,用了php的foreach循环,就可以把wordpress中所有的分类栏目及其栏目下的所有文章都列出来:
<?php //for each category, show all posts $cat_args=array( 'orderby' => 'name', 'order' => 'ASC' ); $categories=get_categories($cat_args); foreach($categories as $category) { $args=array( 'showposts' => -1, 'category__in' => array($category->term_id), 'caller_get_posts'=>1 ); $posts=get_posts($args); if ($posts) { echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> '; foreach($posts as $post) { setup_postdata($post); ?> <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> <?php } // foreach($posts } // if ($posts } // foreach($categories ?>
把这段代码放到的的主题模板上,你将会看到样的结构:
分类栏目1
文章1
文章2
文章3
分类栏目2
文章1
文章2
…
其实如果你了解到get_categories函数和get_posts函数,对两个函数传入自己的参数,可以实现更多更变态的要求,比如指定栏目,指定文章,指定日期,等等
拥有多年WordPress博客/企业建站开发经验,独树一帜的设计,提供最专业的网站设计方案;原创的主题标签语义化,增强网站优化效果。
增强用户体验、提高品牌形象给人留下深刻的印象,那就选择我们,我们的每一款主题都是独一无二的,都有自己的灵魂,每款主题都有各自的配色方案。
遵循现代网页设计的趋势,所有主题都提供完整的响应式布局,优化大桌面显示器以及对平板和智能手机的支持,从而提供一致性的用户体验。
长期及时地在线售后服务和免费升级更新,确保您的网站始终运行在最佳状态,24小时QQ在线的沟通方式免去您的后顾之忧,替您节省网站维护成本。
目前还没有评。