• Can anyone tell me why this doean’t work in category.php but does work in single.php?

    • Subjects include: <?php
      //finds the categories relevant to the post
      foreach((get_the_category()) as $category)
      {
      if($category->name=='University Level Of Study') ;
      $category_id = get_cat_ID( $category->cat_name );
      $category_link = get_category_link( $category_id );
      echo ''.$category->cat_name.' / ';
      }
      ?>
    • I’m trying to exclude certain category links from the search results and i’m using category.php as the search results page for some of my category drop down options on a bespoke search page. I’ve copied the code from a previous project where I was using it in single.php to return a list of category names as links that excluded certain top level links. In this instance I’m using it and it’s returning all the possible categories that are assigned to the post instead of excluding the ones that I don’t want

Viewing 1 replies (of 1 total)
  • Thread Starter rebekahford

    (@rebekahford)

    sorry wrong code example:

    <li>
                                Courses include: <?php
    							  //finds the categories relevant to the post
    								foreach((get_the_category()) as $category) {
    									if(
    									$category->name=='University'||
    									$category->name=='University Level of Study'||
    									$category->name=='University Location'||
    									$category->name=='Vocational Location'||
    									$category->name=='Language Location'
    									)
    									continue;
    									$category_id = get_cat_ID( $category->cat_name );
    									$category_link = get_category_link( $category_id );
    									echo '<a href="'.$category_link.'">'.$category->cat_name.'</a>';
    									}
    							   ?>
                                </li>
Viewing 1 replies (of 1 total)
  • The topic ‘Excluding category links in category.php’ is closed to new replies.