• CodePoet

    (@design_dolphin)


    Is there any way to display the category title without a link?

    Is it possible to call a category title dynamically in a widget title field?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter CodePoet

    (@design_dolphin)

    Found this function and added it to the functions.php file.

    if(!function_exists('get_catbynicename'))
    {
    	function get_catbynicename($category_nicename)
    	{
    	global $wpdb;
    
    	$cat_id -= 0; 	// force numeric
    	$name = $wpdb->get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"');
    
    	return $name;
    	}
    }

    And then adding this code to where you want the cat title to go (based on the sidebar code):

    <?php if ( function_exists('get_catbynicename') ) : else : ?>
    
      <?php if(is_home()) {?>
    
        <?php } ?>
    
        <?php endif; ?>

    But it doesn’t work. What am I doing wrong?

    I could bypass the widget title function by using a text widget, and then placing the title in the text field. But this is a bit of a ugly hack.

    Should be able to pull the current category title based on the current post. Or at least it does using the ‘<?php the_category(‘,’) ?>’ function. The php in the core category file is too complex for me too figure out so far. Preferable is not to change the core files.

    Thread Starter CodePoet

    (@design_dolphin)

    First part solved 🙂

    Category title without link:

    <?php single_cat_title() ?>

    Now how to get this to show in a widget… (without hacking core)

    Thread Starter CodePoet

    (@design_dolphin)

    My bad and my apologies

    Correction: It turns out that this works to show a category title in a post:

    <?php
    foreach((get_the_category()) as $category) {
        echo $category->cat_name . ' ';
    }
    ?>

    http://wordpress.org/support/topic/166373?replies=2

    The previous example didn’t work. I misread the titles on the webpage.

    OK, I’m having a hard time following this. Does the latest code posted work, and where do you put it?

    I am bringing in posts from different feeds and want to identify them automagically without my intervention.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Category title without link | add category title dynamically as widget title’ is closed to new replies.