Forums

[resolved] Dynamic More Tag (2 posts)

  1. freshifreshy
    Member
    Posted 2 years ago #

    I'd like to be able to use the more tag to hide the rest of the post, but then show when you click on the "read more" link, as opposed to forwarding to the post's permalink.

    Any thoughts on how I could do this?

  2. freshifreshy
    Member
    Posted 2 years ago #

    Figured it out. I'm using a function like this.

    function the_dynamic_content() {
    
    	global $page, $pages;
    
    	$content = $pages[$page-1];
    
    	if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
    
    		$content = explode($matches[0], $content, 2);
    
    		$before_more = apply_filters('the_content', $content[0]);
    		$before_more = str_replace(']]>', ']]>', $before_more);
    
    		$after_more = apply_filters('the_content', $content[1]);
    		$after_more = str_replace(']]>', ']]>', $after_more);
    
    		echo '<div class="teaser">'.$before_more.'</div>';
    		echo '<div class="more"><div>'.$after_more.'</div></div>';
    
    		echo '<div class="more-link"></div>';
    
    	} else {
    
    		$content = apply_filters('the_content', $content);
    		$content = str_replace(']]>', ']]>', $content);
    		echo $content;
    
    	}
    
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags