Ich habe folgendes Front-Template erstellt:
Anstelle dieser großen Lorem Ipsum- Blöcke muss ich einen “Auszug” von einer bestimmten Seite zeigen, um diese Box zu füllen (eine bestimmte Anzahl von Zeichen).
Wie erhalte ich einen Seiteninhalt im String-Format, damit ich ihn aussprechen und auf eine bestimmte Anzahl von Zeichen reduzieren kann?
< ?php // would echo post 7's content up until the tag $post_7 = get_post(7); $excerpt = $post_7->post_excerpt; echo $excerpt // would get post 12's entire content after which you // can manipulate it with your own trimming preferences $post_12 = get_post(12); $trim_me = $post_12->post_content; my_trim_function( $trim_me ); ?>
Bitte schön !
< ?php $my_id = 5369; $post_id_5369 = get_post($my_id); $content = $post_id_5369->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); echo $content; ?>
Sie können diesen Code benutzen, es ist eine gute Arbeit Änderung page_id = 19 mit Ihrer Seitenzahl:
< ?php $the_query = new WP_Query( 'page_id=19' ); ?> < ?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> < ?php the_excerpt(); ?> < ?php endwhile;?>
Wenn Sie in der Schleife sind, tun Sie dies:
< ?php $my_excerpt = get_the_excerpt(); if ( $my_excerpt != '' ) { // Some string manipulation performed } echo $my_excerpt; // Outputs the processed value to the page
Oder, wenn Sie eine ID haben, holen Sie sich den Post, dann verklagen Sie die post_excerpt Mitglied Var
z.B
$post = get_post( $post_id ); echo $post->post_excerpt;