WordPress.org

Ready to get started?Download WordPress

Forums

how to use function single_cat_title() (5 posts)

  1. nobita
    Member
    Posted 3 years ago #

    I want to show current category title

    I found this page
    http://codex.wordpress.org/Function_Reference/single_cat_title

    <p><?php single_cat_title('Currently browsing '); ?>.</p>

    Currently browsing WordPress.

    I try this

    if(is_category()){
        $page_title = __("Category Archives :",'obandes');
    	$page_title = $page_title.single_cat_title('', false);
    //ok echo Category Archives : WordPress
    	$page_title = single_cat_title($page_title, false);
    //bad echo  WordPress
    
    }
    
    printf('<div class="h1" id="archives-title">%s</div>',esc_html($page_title));

    I am search other example.

    find twentyten category.php

    <h1 class="page-title"><?php
    	printf( __( 'Category Archives: %s', 'twentyten' ), '<span>' . single_cat_title( '', false ) . '</span>' );
    ?></h1>

    Is this only my ploblem?

    why I have not good result?

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    can you describe what your problem is?

  3. nobita
    Member
    Posted 3 years ago #

    Sorry alchymyth

    function single_cat_title have 2 parameter.
    It is prefix and display parameter.

    the prefix parameter is not work.

    Can my explanation be understood?

  4. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    this is either done on purpose, but undocumented, in the core files (/wp-includes/general-template.php), or an error.

    the resp code snippet is here:

    750      if ( $display )
     751          echo $prefix . $term_name;
     752      else
     753          return $term_name;
     754  }

    so - with the display parameter 'false' to return a string, the prefix is ommitted.

    however, when you know this, you can simply program what you want, as you are working with strings anyway.

  5. nobita
    Member
    Posted 3 years ago #

    I understand Thank you.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.