Site logo

[Support request] images for custom post categories

Home Forums Support [Support request] images for custom post categories

Home Forums Support images for custom post categories

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #2520014
    aik

    Good afternoon.

    I created custom posts for the smartphone section. these have brands in the form of categories

    I created the list of categories or brands of smartphones,

    I would like to be able to make the list of brands appear on the home page with an image and the name of the category

    https://i.ibb.co/FnSRBsD/brand.jpg

    #2520092
    David
    Staff
    Customer Support

    Hi there,

    is this a Custom Taxonomy ? and does it have support for an image ?

    #2520099
    aik

    yes I have support for category image for my custom posts

    https://i.postimg.cc/kXPmYpHG/custom-post.jpg

    #2520218
    aik

    to create the custom posts and the custom categories related to the posts I used the Custom Post Type UI plugin

    #2520279
    David
    Staff
    Customer Support

    You would need to create a custom function eg.

    function show_custom_tax_terms($html) {
        $taxonomy = 'your_custom_tax';
        $terms = get_terms([
            'taxonomy' => $taxonomy,
            'hide_empty' => false,
        ]);
        if ( $terms ) {
            $html = '<ul class="custom-terms">';
            foreach( $terms as $term ) {
                $thumbnail_id = get_term_meta( $term->term_id, 'thumbnail_id', true );
                $image = wp_get_attachment_url( $thumbnail_id );
                $html .= sprintf(
                    '<li><a href="%1$s">
                        <img src="%2$s" alt="%3$s" width="100" height="100" />
                        <span class="title">%3$s<span class="count">%4$</span></span>
                    </a>
                    </li>',
                    get_term_link( $term->slug ),
                    $image,
                    $term->name,
                    $term->count
                );
            }
            $html .= '</ul>';
        }
        return $html;
    }
    add_shortcode('show_terms', 'show_custom_tax_terms' );

    Change the $taxonomy = 'your_custom_tax'; to your taxonomy.

    It will create the [show_terms] shortcode you can add to your page.

    It will need soem CSS to style.

    #2520302
    aik

    do I have to insert the function on the function.php in the theme editor?
    if so, it generated an error, in any case reading the code I don’t understand how it should extrapolate the image relating to the cartegory

    error:

    Uncaught Error: Object of class WP_Error could not be converted to string in wp-content/themes/generatepress/functions.php:148
    Stack trace:
                    get_term_link( $term->slug ),
                    $image,
                    $term->name,
    line 148:       $term->count
    #2520316
    David
    Staff
    Customer Support

    I made an edit to the code above to fix that.

    This doc explains how to add PHP:
    https://docs.generatepress.com/article/adding-php/

    If you’re not using a Child Theme, then DO NOT add it to the parent theme functions.php

    #2520321
    aik

    I proceeded to insert your code with Code Snippets unfortunately it generates an error.

    maybe I explained myself wrong.

    more than a taxonomy what I want to list are the categories related to the custom post

    I currently have 118 brands in the form of categories

    I called the categories “marche”

    https://i.postimg.cc/kXPmYpHG/custom-post.jpg

    so following your guide i should replace the code like this:

    $taxonomy = 'marche';

    #2520410
    aik

    https://i.ibb.co/dmNkKLJ/Snapshot-230203181354.png

    i found the method to list the brands list of my smart phones using tag cloud.

    the background image is missing from this selection.

    also could you suggest me how to change the default css of tag cloud?

    #2520440
    Leo
    Staff
    Customer Support

    the background image is missing from this selection.

    That is a WP core block that does not offer a background image option.

    also could you suggest me how to change the default css of tag cloud?

    What would you like to change? Can you link us to the page in question?

    #2520490
    aik

    https://bdthemes.com/wp-content/uploads/2021/04/3-5-1320x310.png

    I was planning on doing something similar, with the category image inside

    #2520492
    Leo
    Staff
    Customer Support

    The core tag cloud block won’t be able to support this without some substantial custom coding unfortunately.

    Is your screenshot taken from a plugin? If so that might still be your best bet.

    #2520514
    aik

    Yes, it’s Elementor Pro, I abandoned Elementor for your splendid theme, definitely more performing.

    anyway, if i give up the image could i find a method to format the clod tags? or create post archive style formatting for custom categories?

    #2520520
    Leo
    Staff
    Customer Support

    You could try formatting the core cloud tag block with CSS for sure.

    #2520522
    aik

    do you think i can manage to replicate such a thing with only css?

    https://i.ibb.co/FnSRBsD/brand.jpg

Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.