Tagged: 

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

    I have an image where you can click and you will get a list of a particular category ( Pages and posts)
    I have used this code below to trim the length of the Page or Post.

    What I would like to add is a Read More link at the bottom of this to anyone can go to the page or page they see listed.

    Can this be done??

    code is

    // Excerpt length
    function custom_excerpt(){
    ?>
    <script>
    // trim sentence by 150 words
    	function trimByWord(sentence,wordcount = 150) {
    		var result = sentence;
    		var resultArray = result.split(" ");
    		if(resultArray.length > wordcount){
    		resultArray = resultArray.slice(0, wordcount);
    		result = resultArray.join(" ") + "...";
    		}
    		return result;
    	}
    jQuery(window).load(function(){
        jQuery('.post-entry').each(function() {
         	jQuery(".entry-content ").text(function(index, currentText) {
      
         		return trimByWord(currentText);
    		 });
        	jQuery(".entry-title a").text(function(index, currentText) {
       		return trimByWord(currentText,15); // trim title by 15 words
    		 });
        });
    });
    </script>
    <?php
    }
    add_action('wp_head', 'custom_excerpt');

    Thanks

    #838352

    Hey wealthyone,

    I think you can add/insert the read more link after the … in your code:

    result = resultArray.join(" ") + "...";

    Hope this helps.

    Best regards,
    Nikko

    #838557

    Thanks. But what is the code for the Read More link?
    So when lots of posts and pages are shown, then what code will grab the link for each.

    thanks

    #838720

    Hi wealthyone,

    Could you please give us a link to your website, we need more context to be able to help you.

    Best regards,
    Victoria

    #839014

    its a dev site on my desktop.
    I have an image that when clicked will list a all of one category.
    When this list came up, it would show the full post, but adding code above reduced that to set number of words.
    All I would like to do is add an option to have “Read More” at the end of each listed post and then click that link and it takes
    you to the actual post itself.

    Pages are also set up with categories so pages get listed as well.

    If there is a whole bunch of new code that will do that same then I could try that. But I can not find anything else

    thanks

    #840418

    Hi wealthyone,

    We need to see the actual css and html to be able to propose a solution for you. Please get back to us when you get the website to some testing server.

    Best regards,
    Victoria

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