本网站使用 cookie 以确保您在我们的网站上获得最佳体验。通过使用我们的网站,您承认您已阅读并理解我们的隐私政策

求助:怎么让wordpress只调用某个分类的网址?

taomi (UID: 4460) 1月前

429 5

想学大佬搞个米表联盟,创建了一个米表联盟页面,然后用下面代码调用网址模块,发现把首页的所有网址都调用了。请问怎么设置可以只调用某个分类?比如“米表联盟”!

    // 加载网址模块
    foreach($categories as $category) {
        if($category->category_parent == 0){
            $children = get_categories(array(
                'taxonomy'   => 'favorites',
                'meta_key'   => '_term_order',
                'orderby'    => 'meta_value_num',
                'order'      => 'desc',
                'child_of'   => $category->term_id,
                'hide_empty' => 0
            ));
            if(empty($children)){ 
                fav_con($category);
            }else{
                if(io_get_option("tab_type")) {
                    fav_con_tab($children,$category->term_id);
                }else{
                    foreach($children as $mid) {
                        fav_con($mid);
                    }
                }
            }
        }
    } 

 

尾巴,我没有尾巴!
已有评论 (5)
  • amdyyds (UID: 2291) @Ta
    1月前
    1

    不用循环,直接根据slug或id获取分类就行

  • V 王某 (UID: 2766) @Ta
    1月前 (网谋论坛:WM.LT)
    2
    <?php 
    $args=array(
        'orderby' => 'id',
        'cat' => $CID,   // 分类ID
        'posts_per_page' => '12', // 显示篇数
        'order'   => 'desc',
    );
    query_posts($args);
    if(have_posts()) : while (have_posts()) : the_post();?>
    <a href="<?php echo get_permalink();?>"><?php echo get_the_title();?></a>
    <?php endwhile;endif;wp_reset_query();?>
  •  (UID: 75) @Ta
    1月前 (刀是什么样的刀?屌是什么样的屌?)
    3

    楼上正解!

  • taomi (UID: 4460) @Ta
    1月前 (尾巴,我没有尾巴!)
    4
    amdyyds 不用循环,直接根据slug或id获取分类就行

    谢谢

  • taomi (UID: 4460) @Ta
    1月前 (尾巴,我没有尾巴!)
    5
    王某 &lt;?php $args=array( 'orderby' =&gt; 'id', 'cat' =&gt; $CID, // 分类ID ...

    多谢解答

    • 大佬论坛
      6
      登录后才可回帖  登录 注册
狗云本站同款香港KC服务器 ROOVPS 便宜服务器 盾云SCDN 月付只需1元起