Thread Starter
brettr
(@brettr)
This will display the category description for each post within that category while displaying the blog description outside of the category (notice I only have two pages):
<?php
if( ($page_id != 8) && ($page_id != 2))
{
$category = get_the_category();
echo $category[0]->category_description;
}
else
{bloginfo(‘description’);}
?>
page_id = 2 is the About page. However, it doesn’t return an ID when I’m on the about page. So the default category description displays instead. Any suggestions as to why the About page is not returning a page_id?
Thanks,
Brett
While Pages don’t have categories in a visible, practical way to group them (as in the case of posts) – for internal technical reasons [so we were told!] they always belong to the “default” category of your blog. More exactly, to the whatever was the default category in the moment when the Page has been created.
Thread Starter
brettr
(@brettr)
Yes – I understand that pages belong to the default category but why doesn’t the About page have a page_id?
Well, the About Page does have an id – you just said above, it’s = 8.
What I don’t understand: why are expecting that the code you posted would return a Page’s ID? I am not a coder, but there is nothing in that code to display any kind of page ID…
Thread Starter
brettr
(@brettr)
You’re right. I added this:
global $wp_query;
$page_id = $wp_query->post->ID;
But then modified the code to use this:
if( !is_page() )
{
$category = get_the_category();
echo $category[0]->category_description;
}
else
{bloginfo(‘description’);}
I’m looking for the same thing. Like the original question asker, I’m referring to posts, not pages:
I’d like the category description to display when I’m on a post in a certain category. What is the best way to do this?