• Hallo,

    bin ich der einzige dem es nicht gelingt dass das „read more“ vernünftig bei Seiten einzusetzen ?

    Ich möchte auf der Frontpage ein paar Seiten anreissen, das funktioniert via Custom Fields. Aber leider wurde entweder der ganze Text angezeigt oder auf den jeweiligen Seiten (wenn man auf Read more geklickt hat) wurde auch nur der Text bis Readmore angezeigt 🙁

    Jetzt habe ich eine unschöne Lösung gefunden :
    Ich habe die /wp-includes/post_template.php verändert!

    Kann mir jemand erklären wie ich die get_the_content Funktion ändere ohne die post_template.php zu hacken?

    Ich hatte gedacht, das ist der richtige weg in der functions.php:

    remove_filter('get_the_content','???');
    add_filter('get_the_content', 'my_get_the_content');

    Aber was trage ich bei ??? ein?

    Und hier meine neue my_get_the_content, vielleicht kann man meine Änderungen ja noch wo anders VIEL schlauer machen…
    Meine Änderungen sind in Zeile 36-48:

    function get_the_content($more_link_text = null, $stripteaser = 0) {
    	global $id, $post, $more, $page, $pages, $multipage, $preview;
    
    	if ( null === $more_link_text )
    		$more_link_text = __( '(more...)' );
    
    	$output = '';
    	$hasTeaser = false;
    
    	// If post password required and it doesn't match the cookie.
    	if ( post_password_required($post) ) {
    		$output = get_the_password_form();
    		return $output;
    	}
    
    	if ( $page > count($pages) ) // if the requested page doesn't exist
    		$page = count($pages); // give them the highest numbered page that DOES exist
    
    	$content = $pages[$page-1];
    	if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
    		$content = explode($matches[0], $content, 2);
    		if ( !empty($matches[1]) && !empty($more_link_text) )
    			$more_link_text = strip_tags(wp_kses_no_null(trim($matches[1])));
    
    		$hasTeaser = true;
    	} else {
    		$content = array($content);
    	}
    	if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) )
    		$stripteaser = 1;
    	$teaser = $content[0];
    	if ( ($more) && ($stripteaser) && ($hasTeaser) )
    		$teaser = '';
    	$output .= $teaser;
    	if ( count($content) > 1 ) {
    		if ( $more ) {
    			if (is_front_page() ) {
    				$output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-$id\" class=\"more-link\">$more_link_text</a>", $more_link_text );
    			}else{
    				$output .= '<span id="more-' . $id . '"></span>' . $content[1];
    			}
    		} else {
    			if ( ! empty($more_link_text) )
    				$output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-$id\" class=\"more-link\">$more_link_text</a>", $more_link_text );
    			$output = force_balance_tags($output);
    		}
    	}
    	if ( $preview ) // preview fix for javascript bug with foreign languages
    		$output =	preg_replace_callback('/\%u([0-9A-F]{4})/', create_function('$match', 'return "&#" . base_convert($match[1], 16, 10) . ";";'), $output);
    
    	return $output;
    }

    Danke fürs gucken!
    Arson

  • Das Thema „more tag hack in post_template.php – get_the_content“ ist für neue Antworten geschlossen.