• Hi,

    I have the following code below that shows just the categories that the current post is assigned to,

    I need a way of showing all the categories on the blog.

    <div class="categories-title">Tags</div>
    					<div class="categories">
    					<?php
    						$categories = get_the_category();
    						$separator = ' ';
    						$output = '';
    						if($categories){
    						foreach($categories as $category) {
    						$output .= '<p>'.$category->cat_name.'</p>'.$separator;
    						}
    						echo trim($output, $separator);
    						}
    						?>
    					</div>
    				</div>

    Any help is appreciated

Viewing 2 replies - 1 through 2 (of 2 total)
  • I think the best way to do this would be to use the get_categories function.

    I think the code below will do what you’re looking for.

    <?php
    $args = array(
      'orderby' => 'name',
      'order' => 'ASC'
      );
    $separator = ' ';
    $output = '';
    $categories = get_categories($args);
    if ($categories) {
      foreach ($categories as $category) {
        $output .= '<p>' . $category->name.'</p> ' . $separator;
      }
      echo trim($output, $separator);
    }
    ?>
    Thread Starter RyanHipkiss

    (@ryanhipkiss)

    Cheers, I’ll try that.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show all categories, rather than the ones the post is assigned’ is closed to new replies.