Celebrating 7 Years! Get up to $30 off GeneratePress Premium!

[Resolved] Is it possible to include a "Read more" function with this code

Home Forums Support [Resolved] Is it possible to include a "Read more" function with this code

Home Forums Support Is it possible to include a "Read more" function with this code

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #589701
    Tor

    Hi thanks to Tom I found and added this code:

    /* 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="diggs-shop-excerpt">' . apply_filters( 'woocommerce_short_description', wp_html_excerpt($post->post_excerpt,100,'... ') ) . '</div>';
    	}
    }

    Is it possible to add a “Read more” function to the Excerpt?

    Thanks

    GeneratePress 2.1.2
    GP Premium 1.6.2
    #589734
    Leo
    Staff
    Customer Support

    Hi there,

    Not quite sure if I understand.

    Where are trying to add read more?

    #589752
    Tor

    https://area51.lydsenteret.no/produktkategori/bil/bilstereo/

    At the end of the excerpt where there is now …
    Or the whole Excerpt as a link to the product itself.

    #589895
    Tom
    Lead Developer
    Lead Developer

    Give this a shot:

    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="diggs-shop-excerpt">' . apply_filters( 'woocommerce_short_description', wp_html_excerpt($post->post_excerpt,100,'... ') ) . '</div>';
    
                    echo '<p><a href="' . get_permalink( $post->ID ) . '" class="button">Read more</a></p>';
    	}
    }

    Let me know πŸ™‚

    #591855
    Tor

    Thanks Tom, I rebuilt it a bit πŸ˜‰

    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="diggs-shop-excerpt">' . apply_filters( 'woocommerce_short_description', wp_html_excerpt($post->post_excerpt,80,'<a href="' . get_permalink( $post->ID ) . '"><strong>...Les mer</strong></a>') ) . '</div>';
    	}
    }
    #591999
    Tom
    Lead Developer
    Lead Developer

    Perfect πŸ™‚ Thanks for sharing!

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