WordPress.org

Forums

How to customize widget Tag Cloud (21 posts)

  1. evilmc
    Member
    Posted 3 years ago #

    How to customize widget TAG CLOUD like this:

    Now:
    http://i44.tinypic.com/ehiyah.jpg

    Like this, show number and title:
    http://i42.tinypic.com/23wognp.jpg

    thanx

  2. Tara
    Volunteer Moderator
    Posted 3 years ago #

  3. Michael
    Forum Moderator
    Posted 3 years ago #

    you could work with a filter function;
    http://codex.wordpress.org/Plugin_API/Filter_Reference

    example:

    add_filter ( 'wp_tag_cloud', 'tag_cloud_count' );
    function tag_cloud_count( $return ) {
    $tags = explode('</a>', $return);
    $regex = "#(.*title[=]')(.*)( topic.*)#e";
    foreach( $tags as $tag ) {
    $tagn[] = preg_replace($regex, "('$1$2$3&nbsp($2&nbsp;Poster'.(($2!=1)?'a':'').')')", $tag );
    }
    $return = implode('</a>', $tagn);
    return $return;
    }

    engl version:

    add_filter ( 'wp_tag_cloud', 'tag_cloud_count' );
    function tag_cloud_count( $return ) {
    $tags = explode('</a>', $return);
    $regex = "#(.*title[=]')(.*)( topic.*)#e";
    foreach( $tags as $tag ) {
    $tagn[] = preg_replace($regex, "('$1$2$3&nbsp($2&nbsp;post'.(($2!=1)?'s':'').')')", $tag );
    }
    $return = implode('</a>', $tagn);
    return $return;
    }
  4. evilmc
    Member
    Posted 3 years ago #

    @alchymyth, can you tell me where should I put this code?

    Sorry for my english.

  5. Michael
    Forum Moderator
    Posted 3 years ago #

    forgot to say - the code belongs into functions.php of your theme.

  6. evilmc
    Member
    Posted 3 years ago #

    @alchymyth, I add this code into my theme, but nothing changed, everything remains the same.

    I use this code:

    add_filter ( 'wp_tag_cloud', 'tag_cloud_count' );
    function tag_cloud_count( $return ) {
    $tags = explode('</a>', $return);
    $regex = "#(.*title[=]')(.*)( topic.*)#e";
    foreach( $tags as $tag ) {
    $tagn[] = preg_replace($regex, "('$1$2$3&nbsp($2&nbsp;post'.(($2!=1)?'s':'').')')", $tag );
    }
    $return = implode('</a>', $tagn);
    return $return;
    }
  7. Michael
    Forum Moderator
    Posted 3 years ago #

    maybe because of the language -

    this is the html code of one tag within the tag cloud (english site):

    <a href='http://localhost/wordpress/keywords/articles/' class='tag-link-110' title='2 topics' style='font-size: 14.3pt;'>articles</a>

    try to see what this word is in your language:

    topic

    and then edit the filter code accordingly.
    can you post a link to your site?

  8. evilmc
    Member
    Posted 3 years ago #

    Yes, this is my website: http://www.lajkuj.rs/

    And I use this permalinks: http://i39.tinypic.com/1tspjc.jpg

  9. Tara
    Volunteer Moderator
    Posted 3 years ago #

    i tested the English version and it works fine for me.

  10. Michael
    Forum Moderator
    Posted 3 years ago #

    @evilmc - I see, it is (partly) working;

    try to change the one line in the code to:

    $regex = "#(.*title[=]')(.*)( tem.*)#e";

    if you don't see it in your browser, try to clear the browser cache - reload the web page or try pressing 'CTRL F5'

  11. evilmc
    Member
    Posted 3 years ago #

    @alchymyth, now works!

    big thanx! :)

  12. evilmc
    Member
    Posted 3 years ago #

    @alchymyth, can you tell me what to delete, shows only the numbers (don't show Poster).

    Thanx

  13. Michael
    Forum Moderator
    Posted 3 years ago #

    this is what I see: http://imageshack.us/photo/my-images/41/posteram.jpg/

    have you tried to clear the browser cache or re-loaded the web page?

    if you still only see the numbers, please past the full code of the filter function ( see http://codex.wordpress.org/Forum_Welcome#Posting_Code )

  14. evilmc
    Member
    Posted 3 years ago #

    Yes, yes...and works! I crear my browser cache, but now I won't show only numbers tags, don't show title(poster-a).

  15. Michael
    Forum Moderator
    Posted 3 years ago #

    ok, I get it -

    change the filter function to:

    add_filter ( 'wp_tag_cloud', 'tag_cloud_count' );
    function tag_cloud_count( $return ) {
    $tags = explode('</a>', $return);
    $regex = "#(.*title[=]')(.*)( tem.*)#e";
    foreach( $tags as $tag ) {
    $tagn[] = preg_replace($regex, "('$1$2$3&nbsp($2)')", $tag );
    }
    $return = implode('</a>', $tagn);
    return $return;
    }
  16. evilmc
    Member
    Posted 3 years ago #

    I get this error:
    Parse error:
    syntax error, unexpected ';', expecting T_PAAMAYIM_NEKUDOTAYIM in /home/www/lajkuj.rs/wp-content/themes/BlueMotion/functions.php on line 306

  17. Michael
    Forum Moderator
    Posted 3 years ago #

    please paste the full code of functions.php into a http://pastebin.com/ and post the link to it here - see: http://codex.wordpress.org/Forum_Welcome#Posting_Code

  18. evilmc
    Member
    Posted 3 years ago #

    This is my function.php : http://pastebin.com/0x5ZBEWq

  19. Michael
    Forum Moderator
    Posted 3 years ago #

    I have no idea what could cause the error - I put the same code into functions.php of my theme, and there is no error message in the corresponding line.

    try to remove the section again to see if that changes something:

    add_filter ( 'wp_tag_cloud', 'tag_cloud_count' );
    function tag_cloud_count( $return ) {
    $tags = explode('</a>', $return);
    $regex = "#(.*title[=]')(.*)( tem.*)#e";
    foreach( $tags as $tag ) {
    $tagn[] = preg_replace($regex, "('$1$2$3&nbsp($2&nbsp;Poster'.(($2!=1)?'a':'').')')", $tag );
    }
    $return = implode('</a>', $tagn);
    return $return;
    }
  20. evilmc
    Member
    Posted 3 years ago #

    @alchymyth, now works!

    big, big for your help!

  21. evilmc
    Member
    Posted 2 years ago #

    It's possible this code change for exclude post tags?

    This is image in my website:
    http://i50.tinypic.com/mt82ys.png

    I wont exclude tag 'slajder' (slide=English), bacause this tag show only for my FLEX SLIDER in my WP Theme.

    Thanx

Topic Closed

This topic has been closed to new replies.

About this Topic