0

Following is my categories page. It's listing the all categories in the page. But when <a href> gets blank value here. see the attached screen shot. Why href is blank here

 li><a href="<?php echo esc_url(   $category_link ); ?>"><?php echo $cat- >name; ?></a></li>

Here the the complete code

<? php
    /*
    Template Name: Categories
    */
        get_header(); 
        $cats =  get_categories();
        $num_cats  = wp_count_terms('category'); 
        $count = $num_cats;  // Total Categories
        $linetotal=round($count/3); // Part of Category
        $cat1 = get_query_var('cat');
        $category_link = get_category_link( $cat1 );    
        ?>
        <!-- Main body section begins -->   
    <div class="row">   
      <div class="medium-4 large-4 columns category_list">
        <ul>
            <?php
          $totalcount = 1;
          $totalpart = 1;
          foreach($cats as $cat): ?>
            <li><a href="<?php echo esc_url( $category_link ); ?>"><?php echo $cat->name; ?></a></li>
            <?php
            if($totalcount % $linetotal == 0 && $totalpart < 3) { 
              echo '</ul></div><div class="medium-4 large-4 columns category_list"><ul>';
                  $totalpart++;
            }
            $totalcount++;
          endforeach;?>
        </ul>
      </div>
     </div>
    <?PHP get_footer(); ?>

enter image description here

Any suggestions will be appreciated.

  • What does $category_link look like? – birgire Jun 25 '14 at 10:09
  • @birgire means? i do not understand the question. $cat1 = get_query_var('cat'); $category_link = get_category_link( $cat1 ); – Riffaz Starr Jun 25 '14 at 10:13
  • I mean, what's the value of $category_link? – birgire Jun 25 '14 at 10:17
  • 1
    I just want to make sure it's not empty. So did you check out echo $category_link;? – birgire Jun 25 '14 at 10:19
  • 1
    I thought so, the question title is then somewhat misleading, since this isn't esc_url() fault ;-) So you need to debug things further up. Try to echo all your variables and see if you can spot where the problem starts. – birgire Jun 25 '14 at 10:30
1

This is probably not the template for a category archive, but for a custom page template because of this:

/*
Template Name: Categories
*/

The query variable 'cat' is not set in pages.

Move get_category_link( $id ); inside the foreach.

<li><a href="<?php echo esc_url( get_category_link( $cat->term_id ) ); ?>"><?php echo $cat->name; ?></a></li>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.