The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

how to use function single_cat_title() (5 posts)

  1. nobita
    Posted 5 years ago #

    I want to show current category title

    I found this page

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

    Currently browsing WordPress.

    I try this

        $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>' );

    Is this only my ploblem?

    why I have not good result?

  2. Michael
    Forum Moderator
    Posted 5 years ago #

    can you describe what your problem is?

  3. nobita
    Posted 5 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. Michael
    Forum Moderator
    Posted 5 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
    Posted 5 years ago #

    I understand Thank you.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.