• Resolved fsalamic

    (@fsalamic)


    This is the code that I am using , but how can I edit it to a custom taxonomy (for example – movies)?
    Can someone help me?

    <?php
    $hide_uncategorized = true;
    $limit = 30;  // Show this many entries per page
    $range = 5;  // Show this many nav bar page links (other than first & last).
    $args = array('orderby' => 'name', 'order' => 'ASC');
    if ($hide_uncategorized) $args['exclude'] = '0';
    $categories = get_categories($args);
    if ($categories) :
       // For some unknown reason, $categories has no [0] entry at times, so renumber.
       $categories = array_merge($categories,array());
       if (isset($_GET['page'])) {
          $page = $_GET['page'];
       } else {
          $page = 1;
       }
       $start = ($page - 1) * $limit;
       $currletter = '';
       echo '<ul class="category_list">';
       for ($i=$start;$i<($start + $limit);++$i) {
          if ($i < sizeof($categories)) {
             $cat =  $categories[$i];
             $catletter = strtoupper(substr($cat->name,0,1));
             if ($currletter != $catletter) {
                if ($currletter != '') echo '</ul>';
                $currletter = $catletter;
                echo "<p> - $catletter - </p>";
                echo '<ul class="list-group">';
             }
             echo '<li class="list-group-item"><a href="' . get_category_link( $cat->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $cat->name ) . '" ' . '>' . $cat->name.'</a>  ';
             echo '</li>';
          }
       }
       echo '</ul>';
    else:
       echo '<h2></h2>';
       echo 'There are no Categories to list';
    endif;?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • When you are querying a custom taxonomy, you have to use get_taxonomies instead of get_categories.

    The args:
    $args = array('name' => 'movie', 'orderby' => 'name', 'order' => 'ASC');

    The query:
    $categories = get_taxonomies($args);

    Thread Starter fsalamic

    (@fsalamic)

    Thanks ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to change this code to different taxonomy’ is closed to new replies.