Please help me with this code get_categories

Discussion in 'WordPress' started by Divvy, Feb 24, 2016.

  1. #1
    Hello guys,

    Maybe you can help me with this problem.
    I have this code in my site to display some categories with posts:

    <?php $col_no = 1;
    foreach(get_categories() as $cat=>$sub_cat) { ?>
    <div class="col-md  <?php echo 'col-no-'.$col_no; ?>">
    
    <h3><a href="<?php echo get_category_link($sub_cat->cat_ID); ?>"><span><?php echo $sub_cat->cat_name; ?></span></a></h3>
    <div class="list">
        <ul class="blocksingle">
    
        <?php query_posts('category_name='.$sub_cat->category_nicename.'&posts_per_page=5'); ?>
        <?php while ( have_posts() ) : the_post(); ?>
            <?php
            $post_external_link = (get_post_meta(get_the_ID(),'post_external_link',true))?get_post_meta(get_the_ID(),'post_external_link',true):'#';
            $new_post_added = (get_post_meta(get_the_ID(),'new_post_added',true))?'<span class="new_txt">'.get_post_meta(get_the_ID(),'new_post_added',true).'</span>':'';
    if(get_field( "nofollow_tag" )) { $nofollow_tag = 'rel="nofollow"'; }
    else { $nofollow_tag = ''; }
            ?>   
       
            <li><a target="_blank" href="<?php echo $post_external_link; ?>" title="<?php the_title(); ?>" <?php echo $nofollow_tag; ?>><span class="li_list"><?php the_title(); ?></span>
            <?php echo $new_post_added; ?></a><a title="Click to visit <?php the_title(); ?>" href="<?php the_permalink(); ?>"><span class="review"></span></a></li>
        <?php endwhile; ?>   
        </ul>
    </div>
    <div class="list_bottom"></div>
       
    </div>
    
    <?php $col_no++;
    if($col_no == 13){
        break;
    }} ?>
    PHP:
    Everything is good with the code, everything is working fine, expect... I need to show some spicific categories, is it possible?
    If yes, how?

    Probably I need to edit this line right?
    
    <?php $col_no = 1; foreach(get_categories() as $cat=>$sub_cat) { ?>
    PHP:
    Waiting for someone who can help me :)

    Thanks!
     
    Divvy, Feb 24, 2016 IP
  2. Divvy

    Divvy Well-Known Member

    Messages:
    785
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    Ok, I discovered how to do it by doing:

    foreach(get_categories('include=31,3,9,14,4,6,26,5') as $cat=>$sub_cat) { ?>
    PHP:
    But is possible to show per specific order? :)

    EDIT:

    I also tried this:

    
    <?php
    $args = array(
    'hierarchical'             => 1,
    'orderby'                  => 'id',
    'order'                    => 'ASC',
    'include'                  => '31,3,14,9,4,6,26,5',
    );
    $col_no = 1;
    foreach(get_categories($args) as $cat=>$sub_cat) { ?>
    PHP:
    But how to display categories in a particular order?
    Can I take that output and just call them in the order I want them? (ex: 1,3,4,2,5,0)
     
    Last edited: Feb 24, 2016
    Divvy, Feb 24, 2016 IP