WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] 'Read more' (6 posts)

  1. davejampole
    Member
    Posted 1 year ago #

    I want to use 'Read more' in a Secondary Widget Area. From what I've read on virtually every 'read more' plugin, they are intended for, and limited to, the main page.

    I would also like to have 'read less' functionality so that when a viewer is finished reading the material, they can shrink it back.

    Anyone know of a 'Read more' that would work in my situation?

    Thanks

  2. ruphel
    Member
    Posted 1 year ago #

    Dave

    Try this

    Place the the following in your functions.php

    <?php
    function limit_words($string, $word_limit) {
    
    	// creates an array of words from $string (this will be our excerpt)
    	// explode divides the excerpt up by using a space character
    
    	$words = explode(' ', $string);
    
    	// this next bit chops the $words array and sticks it back together
    	// starting at the first word '0' and ending at the $word_limit
    	// the $word_limit which is passed in the function will be the number
    	// of words we want to use
    	// implode glues the chopped up array back together using a space character
    
    	return implode(' ', array_slice($words, 0, $word_limit));
    
    }
    ?>

    then,

    <?php echo limit_words(get_the_excerpt(), '27'); ?>

    '27' - being the amount of words in an excerpt,( your widget area being small)

    then,

    <?php the_excerpt(); ?><?php echo apply_filters('the_excerpt',get_the_excerpt().'<a href="'.get_permalink().'"> read more </a>'); ?>

    I hope that works for you on the first part of your question

  3. davejampole
    Member
    Posted 1 year ago #

    ruphel,

    Thanks for the reply.

    I placed the function limit_words, the echo limit_words and the_excerpt all in my function.php and saved the changes.

    When I opened the website, nothing has changed - the content in the widget area in the original length with no "read more" showing.

    Any idea what I'm doing wrong, or not doing?

    Dave

  4. davejampole
    Member
    Posted 1 year ago #

    Solved my problem. Just on the off-chance someone else wants to do the same thing, check out twinpictures.de's Collapse-O-Matic. It works EXACTLY as I want, it is flexible and painless!!

    I've used it a number of times throughtout this site <arklatexmoaa.org>, but before this instance, always to expand/collapse lists; never thought about using it on text. Dumb me.

  5. ruphel
    Member
    Posted 1 year ago #

    Glad it worked out for you.

    Dave

    Nice site, seen what you were aiming for, great result.

  6. davejampole
    Member
    Posted 1 year ago #

    Thanks, I appreciate the kind words.

    I guess one of things to take from this is that there is usually more than one way to solve a problem. I've just grown partial to twinpictures.de's widgets.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags