category image change

NapitWPTech Theme Support Forums Masonry Brick category image change

This topic contains 9 replies, has 2 voices, and was last updated by  Bishal Napit 9 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #383

    polov
    Participant

    Hello,
    you gave me the code to add the category on my Home page, it’s perfect (I can not find the topic), but now I would like to put an image in front of the category name

    the code is:
    $ categories_list = get_the_category_list (esc_html __ (‘,’, ‘masonry-brick’));
    if ($ categories_list && masonry_brick_categorized_blog ()) {
    printf (‘<span class = “cat-links”>’. wp_kses (__ (‘<i class = “fa -fold-open”> </ i>% 1 $ s’, ‘masonry-brick’), array (‘i’ => array (‘class’ => array ()))). ‘</ span>’, $ categories_list); // WPCS: XSS OK.
    }}

    – would it be possible to replace the <i class = “fa fa-folder-open”>
    by an image and that this picture changes according to the category?

    for example:
    cat = 12 with image1.jpg
    cat = 25 with image2.jpg
    etc …

    thank you

    #386

    Bishal Napit
    Keymaster

    @polov

    If you can code that on your own then, you may be able to achieve that via the child theme. However, category does not have the feature of image upload option to make the image featured so, you may need to search in the WordPress plugin directory, which allows you to do the same. So, can you search there and manage accordingly?

    Thanks.
    Bishal Napit

    #387

    polov
    Participant

    the problem is that i do not know the conditions in PHP: if – else with printf…
    here we have an image in <i class = “fa -fold-open”> that is common for all categories

    – would it be possible to replace with a conditon that would say when cat 18 put this <i …> or another image, when cat 23 put another image, etc …?

    I already have PHP in my child theme, templates

    ok
    but I will look for my side …
    thank you

    • This reply was modified 9 months, 1 week ago by  polov.
    #389

    Bishal Napit
    Keymaster

    @polov

    Maybe, you can try out this plugin: https://wordpress.org/plugins/categories-images/ available via the WordPress plugin directory and manage accordingly as stated in their docs in the same page about how to use the same?

    Thanks.
    Bishal Napit

    #390

    polov
    Participant

    thank you for the plugin I will test it …

    but I prefer a direct code in my PHP
    I think I managed to get the code into my functions.php file
    I have to improve with a switch (case) so as to avoid too much if else
    but it’s going on …

    #393

    Bishal Napit
    Keymaster

    @polov

    For that, without the plugin with switch or if case, the condition will probably be the same and long. Hope you can do that.

    Thanks.
    Bishal Napit

    #395

    polov
    Participant

    yes, for my site, for the length it is a visual choice if I put images on all the categories or if I make connections (same image for several categories)
    my if-else is working now, but I have to choose for the image/category ratio

    instead of if-else I’m going to make a switch:
    switch ()
    case 0:
    printf ();
    break;

    for the plugin it adds a picture by category, but you have to manually add PHP code in each Template, and there I did not understand, so I uninstalled it because I just want to have the images on homepage, and also because I want to limit the number of plugins

    • This reply was modified 9 months ago by  polov.
    #397

    Bishal Napit
    Keymaster

    @polov

    Ok. Do let me know if you have got any further query regarding to the theme. I will try to help you on those as far as possible.

    Thanks.
    Bishal Napit

    #398

    polov
    Participant

    Thank you for your help

    #399

    Bishal Napit
    Keymaster

    @polov

    Ok. Not a problem at all. I will probably try to help you on the theme issue as far as possible.

    Thanks.
    Bishal Napit

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.