Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1263010

    Hello everyone,
    I want to reduce the Excerpt length of the Enfold Latest-News Sidebar Widget und put a “read more” link under it, that links to the respective blog post. I tried various recommended solutions, like PHP Snippets or installing the “Advanced Excerpt Plugin”. Sadly nothing seems to work. Can you please help me?

    Thanks in advance.
    Julian

    #1263250

    Can somebody help?

    #1263299

    well there is a more complex way of having a substituted edited : class-framework-widgets.php
    on that it will be possible to have the Read more insert translatable with avia_framework.

    but a fast way is to put this in child-theme functions.php:
    on my opinion it will be better to shorten the amount of words in that excerpt than to have letter shortening.

    function custom_news_excerpt(){
    ?>
    <script>
    (function($){
        function trimByWord(sentence,wordcount = 5) {
            var result = sentence;
            var resultArray = result.split(" ");
            if(resultArray.length > wordcount){
            resultArray = resultArray.slice(0, wordcount);
            result = resultArray.join(" ");
            }
            return result;
        }
    
        $(document).ready(function(){
            $('.news-content').each(function() {
            	 var newsLink = $(this).find('.news-link').attr('href');
                 $(this).find('.news-excerpt').text(function(index, currentText) {
                    return trimByWord(currentText);
                 });
                 $(this).find('.news-excerpt').append('<div class="read-more-link"><a class="more-link" href="'+newsLink+'">Read more<span class="more-link-arrow"></span></a></div>');
        	});
    });
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'custom_news_excerpt');
    #1263307

    here is the edited class-framework-widgets.php
    see lines 1020ff
    Pastebin Link

    then you only need the excerpt shortener in additon to this:

    function custom_news_excerpt(){
    ?>
    <script>
    (function($){
        function trimByWord(sentence,wordcount = 5) {
            var result = sentence;
            var resultArray = result.split(" ");
            if(resultArray.length > wordcount){
            resultArray = resultArray.slice(0, wordcount);
            result = resultArray.join(" ");
            }
            return result;
        }
    
        $(document).ready(function(){
            $('.news-content').each(function() {
            	 var newsLink = $(this).find('.news-link').attr('href');
                 $(this).find('.news-excerpt').text(function(index, currentText) {
                    return trimByWord(currentText);
                 });
        	});
    });
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'custom_news_excerpt');
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.