Viewing 4 replies - 1 through 4 (of 4 total)
  • what code are you finally using?

    to prevent the output to be shown on page 2 etc, wrap the code into a conditional statement using is_paged()https://codex.www.ads-software.com/Function_Reference/is_paged

    example:

    <?php if( !is_paged() ) : ?>
    YOUR CODE
    <?php endif; ?>
    Thread Starter seeiran

    (@seeiran)

    Hi
    many thanks for your help.

    when i display all the posts in category x, that i want to display a list of all the categories that all those posts use.

    <?php
    //cycle through posts and collect all category ids and tags ids used on these posts
    $current_cat = get_query_var('cat');
    $all_cats = array();
    if (have_posts()) :
      while (have_posts()) : the_post();
        $cats = get_the_category();
        if ($cats) {
          foreach($cats as $cat) {
            if ($cat->term_id != $current_cat) {
              $all_cats[$cat->term_id] = $cat->term_id;
            }  //if ($cat->cat_ID
          } //foreach
        } // if ($cats)
      endwhile;
    endif;
    rewind_posts();
    // now display all cats and tags we collected
    $types[0] = 'category';
    foreach ($types as $type) {
      if ($type == 'category') {
        if ($all_cats) {
          $term_ids = $all_cats; //implode(',', $all_cats);
          //wp_list_categories('include='.$term_ids.'&title_li=Categories');
        }
      } 
    
      $taxonomy = $type;
      $args = 'include='.implode(',', $term_ids);
      $terms = get_terms( $taxonomy, $args );
      if ($terms) {
        foreach($terms as $term) {
          if ($term->count > 0) {
            echo '<b>' . '<a href="' . esc_attr(get_term_link($term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name. '/ </b> ';
          }
        }
      }
     }
    ?>
    Thread Starter seeiran

    (@seeiran)

    hi
    may i help you?
    when i display all the posts in category x, that i want to display a list of all the categories that all those posts use.(not page per post)

    Thread Starter seeiran

    (@seeiran)

    when i display all the posts in category x, that i want to display a list of all the categories that all those posts use.(not page per post)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show Related Categories in Cat. view’ is closed to new replies.