WordPress.org

Ready to get started?Download WordPress

Forums

Category title without link | add category title dynamically as widget title (5 posts)

  1. design_dolphin
    Member
    Posted 6 years ago #

    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?

  2. design_dolphin
    Member
    Posted 6 years ago #

    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.

  3. design_dolphin
    Member
    Posted 6 years ago #

    First part solved :)

    Category title without link:

    <?php single_cat_title() ?>

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

  4. design_dolphin
    Member
    Posted 6 years ago #

    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.

  5. mcanady
    Member
    Posted 5 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic