[Resolved] Applying CSS to hook content

Home Forums Support [Resolved] Applying CSS to hook content

Home Forums Support Applying CSS to hook content

  • This topic has 6 replies, 2 voices, and was last updated 7 years ago by Tom.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #308764
    David
    Staff
    Customer Support

    Hi Tom and team,

    im a little out of depth here, i have cobbled together the below PHP snippet which puts the product (post) excerpt into the shop loop. Now i dont know how to style the excerpt using CSS. I have looked at creating DIV and Classes etc but thats beyond me.

    Any ideas? If not i am going to through it at woo. BTW the PHP works but again if there is anything amiss or could be trimmed down your advice would be much appreciated.

    
    /* Adding excerpt to shop page */
    add_action( 'woocommerce_after_shop_loop_item', 'diggs_custom_shop_item', 5);
    function diggs_custom_shop_item() {
    	global $post;
    	
    	/* product excerpt  */
    	if ( $post->post_excerpt ) {
    		echo apply_filters( 'woocommerce_short_description', $post->post_excerpt );
    	}
    }
    
    #308809
    Tom
    Lead Developer
    Lead Developer

    You could try something like this:

    /* Adding excerpt to shop page */
    add_action( 'woocommerce_after_shop_loop_item', 'diggs_custom_shop_item', 5);
    function diggs_custom_shop_item() {
    	global $post;
    	
    	/* product excerpt  */
    	if ( $post->post_excerpt ) {
    		echo '<div class="my-selector">' . apply_filters( 'woocommerce_short_description', $post->post_excerpt ) . '</div>';
    	}
    }

    Then you can style it with:

    .my-selector {}

    #308900
    David
    Staff
    Customer Support

    thanks Tom – as usual you make it so damn easy (and so obvious!)

    #308910
    David
    Staff
    Customer Support

    Hi Tom

    could you help, the post excerpt is a variable length, i want to limit the number of characters or words displayed in the .my-selector. Any ideas?

    #309015
    Tom
    Lead Developer
    Lead Developer

    Perhaps wrapping your content in this function would help: https://codex.wordpress.org/Function_Reference/wp_trim_words

    #309077
    David
    Staff
    Customer Support

    Thanks Tom – case closed

    #309164
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

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