Forums

how to add line break and style to page / category names (5 posts)

  1. lucascorato
    Member
    Posted 1 year ago #

    Hi all!

    My site: http://fot.lucascorato.com (still under development)

    My objective: I want to have a bilingual sidebar without using translation plugins

    My problem: I'm trying to find a way of having category and page names in two lines, so that the first is in english and the second is in portuguese AND I want one to be bold and the other regular, or one white and the other gray, more ore less like this:

    category 1
    categoria 1
    category 2
    categoria 2

    page 1
    página 1
    page 2
    página 2

    and so on... hope it's clear enough.

    The only thing I can do is add non-braking spaces & n b s p but that gives kind of unpredictable results, and is not very multi-browser friendly

    I have searched A LOT and couldn't find anything, only thing I found was some method of replacing a character (like a comma , for instance) for a
    but couldn't make it work.

    I guess such fields on my WP admin page, when creating or modifying a page / category, won't accept any code and styling, right?

    Any help is great appreciated, since I don't want to have double pages and double posts and double sites only to have a bilingual sidebar.

    Thanks a lot!

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    I think the way to go here is with wp nav menu You can make your own menu with categories,pages and custom links under Appearance > Menus.

    I made this menu for categories once and it relies heavily on replacing and matching text. Just put this in your theme's functions.php:

    function parse_category_links($match) {
    
    $pattern = '/title="View all posts filed under (.*?)"/';
    $replacement = 'title="View all posts filed under '.$match[4].'"';
    $match[3] = preg_replace($pattern,$replacement,$match[3]);
    $list_item ='<li class="cat-item'.$match[1].'"'.$match[2].'><a'.$match[3].'>'.$match[4].'</a></li>';
    
    // you can translate the "View all posts filed under" to Portuguese
    $replacement = 'title="View all posts filed under '.$match[5].'"';
    
    $match[3] = preg_replace($pattern,$replacement,$match[3]);
    $list_item .="\n\t".'<li class="cat-item'.$match[1].'"'.$match[2].'><a'.$match[3].'>'.$match[5].'</a></li>';
    return $list_item;
    
    }
    function split_category_links($text) {
    
    	$pattern = '/<li class="cat-item(.*?)"(.*?)><a(.*?)>(.*?),(.*?)<\/a>\n+<\/li>/';
    	$text = preg_replace_callback($pattern,'parse_category_links',$text);
     	return $text;
    
    }
    
    add_filter('wp_list_categories','split_category_links');

    If you want the same for pages just let me know, but I think wp_nav_menu is a better solution.

  3. keesiemeijer
    moderator
    Posted 1 year ago #

    Forgot to mention that it works on comma separated categories like so category,categoria

  4. lucascorato
    Member
    Posted 1 year ago #

    keesiemeijer, thanks a lot for your feedback, after days searching for an answer you have shed the first real light on the subject!

    since i'm really new to css and specially to php, I think I only got like 50% of what you said before, but - oh now noob I am! - I had never given a try on the custom menus!

    and guess... it's got everything I needed!

    take another look and you will see I did excatly what I wanted: http://fot.lucascorato.com

    thank you very very much again!

  5. keesiemeijer
    moderator
    Posted 1 year ago #

    You're welcome. Nicely done. So I guess the wp_nav_menu allows tags like "<br />" and "<i>".

Topic Closed

This topic has been closed to new replies.

About this Topic