I’ve been trying the following code out in a million combinations, but can’t seem to get it working. I was hoping someone could help me identify the problem.
<?php if (in_category('mac') && in_category('pc')) {
echo 'computer';
} else {
single_cat_title('','false');
} ?>
So the first half of this works – my html will display the word ‘computer’ when the post is in both the mac and pc categories. But the ‘else’ statement doesn’t work, it’s meant to display the category name when the first condition isn’t met, but instead it seems to display nothing at all.
Any help is greatly appreciated.
Cheers,
Glen
Something I have been struggling with for a while as I am a novice. On every page I have an instruction to GET Page Title:
<?php echo get_the_title( $ID ); ?>
However as some of my pages are Categories when you are on this page it returns “Untitled”.
What I would like to do is one piece of code which GET Page Title but if there’s no page title get category title instead else do nothing, output blank, “”.
I know how to get category title:
<?php single_cat_title(); ?>
However I cannot combine the two to achieve what I need.
Any help would be much appreciated.
Cheers,
James
]]>i edit archive.php so it sorts posts by comment count in certain categories. However, by doing this neither single_cat_title() or category_description() show the category name/description. Why is that? This is my code:
<?php if(is_category( array(25))) { query_posts(array('orderby' => 'comment_count')); } elseif(is_category( array(96))) { query_posts(array('orderby' => 'comment_count', 'posts_per_page' => '20')); } ?>
This goes to the very beginning of archive.php.
Could you please give me a hand here?
Thank you
]]><?php $current_category = single_cat_title("", false); ?>
<span class="category-title"><?php echo $current_category; ?></span>
This is what i’m using to display the Category Name in archive, but i need some code to display it’s term_ID. I’m Using Custom Post Type and this a custom taxonomy. I seriously don’t know what it’s called.. but I know it’s a Custom Post Type Category.
I tried the getCurrentCatID() function not working.
Also tried this $cat = get_category( get_query_var( ‘cat’ ) );. But also not working.
<?php
global $wp_query;
$category = $wp_query->get_queried_object();
?>
Tried everything. But NOTHING worked.
*Hope you guys can help me with this. Stuck here forever.
By the way, i’m trying to get the ID so i can get the child categories and display them in DROPDOWN BOX. Thanks
When you go to any tag page single_cat_title returns wrong category – in this case just one category called “Aktualno?ci” (ID 1). You can see the wrong title in metatags (<title></title>) and above the content.
Please check it there: e.g. https://www.bise.pl/tag/promocje-w-bankach/ – there should be the title: “Promocje w bankach”, not “Aktualno?ci” which is regular category: https://www.bise.pl/category/aktualnosci/ – one of many.
Thank you in advance.
]]>I’m very new to WordPress and excited to learn everything I can from it. I have a question that I hope is simple enough to answer.
I want to display the category links on the side of my page, but I want to exclude the title of the current category page it’s on.
So for example my page is on a Category1 page, and on the other category link titles, it shows up as
Category1
Category2
Category3
But I want the category title that the page is currently on (Category1 for example) to be excluded from the list. How would I go about doing this?
]]>I have just upgraded to version 3.0, and single_cat_title seems to have stopped working in my array, the category title won’t display anymore.
There is a [resolved] post a bit further down from this one, but it is NO help. He resolved it himself with very little details and I’m having the same problem! The original poster had said he got around the problem by using get_cat_name instead, but I’m confused and that doesn’t do anything but cause other problems within my code. We are both apparently using the same theme because our code is the exact same.
And if you couldn’t tell, I’m still pretty fresh to php.
Help!? Thanks!
<?php
// enter the IDs of which categories you want to display
$display_categories = array(3,24,7,12,174,15,41,9,8,11,25,16,72);
foreach ($display_categories as $category) {
$count = 0; // Set the post counter ?>
<div class="clearfloat">
<?php query_posts("showposts=4&cat=$category"); // Set showposts to 4 - 1 with excerpt and 3 without
$wp_query->is_category = false;
$wp_query->is_archive = false;
$wp_query->is_home = true;
?>
<h3><a href="<?php echo get_category_link($category);?>">
<?php
// name of each category gets printed
single_cat_title(); ?>
</a></h3>
]]>I have just upgraded to version 3.0, and single_cat_title seems to have stopped working in my array, the category title won’t display anymore
here is the code, i’d really appreciate any assistance on this
<?php
$display_categories = array(8,1,28,11);
foreach ($display_categories as $category) { ?>
<div class="clearfloat">
<?php query_posts("showposts=1&cat=$category");
$wp_query->is_category = false;
$wp_query->is_archive = false;
$wp_query->is_home = true;
?>
<h3><a href="<?php echo get_category_link($category);?>">
<?php single_cat_title(); ?>
</a>
</h3>
]]><?php wp_list_bookmarks(‘title_li=&categorize=0&show_name=1&show_description=1&category_name=single_cat_title()‘); ?>
..bat it dosn’t work …. please help me…
Thank for all
]]>It works fine no problem however it only shows the parent category and not the child category that the post is actually in for instance
I currently have
POST TITLE – CARS
but would like
POST TILE – AUDI
Where AUDI is a child of the category CARS
Hope someone can help because I can’t find answer anywhere on Google or the Codex
And also I can’t work out how to make the single_cat_title link to the child archive page either it always links to the post page instead
]]>