0
votes

I have a simple WordPress installation in my test site. I have no plugins and no special code to exclude (or include) categories in my pages (nothing special for this in functions.php)

I have posts in my categories "people", "projects". However, only posts from my category "places" are visible. What's more, if I go to http://[my-test-site]/category/people, I see nothing displayed in the following code (I have a "category-people/php" page)

$categories = get_the_category();
$category = $categories[0]->slug;
echo '<br/>the category is:' . $category . "<br/>";

The same code above in my front-page.php shows the category as "places". This is very strange. I expect the front-page.php to have no categories (I am not including or excluding any categories by any code or plugin)

Could someone please help me understand what's going on? I've tried changing the WordPress Permalinks Settings to all possible, but it still doesn't work. This is my .htaccess file

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Any help please? I'm getting desperate and seriously behind schedule on my assignment.

Thanks! Anjaan

1

1 Answers

0
votes

You getting just first category slug with $categories[0]->slug. You should to get all categories slug from the loop, like:

foreach( get_the_category() as $category ){ 
  echo '<br/>the category is:'.$category->slug."<br/>";
}