Obtenga el contenido de una página específica (por ID)

12

Tengo la siguiente plantilla de portada:

Enlugardeesosgrandesbloques Lorem Ipsum , necesito mostrar un "extracto" de una página específica para llenar ese cuadro ( un cierto número de caracteres).

¿Cómo obtengo el contenido de una página en formato de cadena para poder hacer eco y recortar a un cierto número de caracteres?

    
pregunta Samuel Stiles 04.06.2013 - 15:51

6 respuestas

19
<?php

// would echo post 7's content up until the <!--more--> 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 );

?>
    
respondido por el Marc Dingena 04.06.2013 - 16:06
18

¡Aquí tienes!

<?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;
?>
    
respondido por el ameer hamza 16.11.2015 - 09:13
2

puedes usar este código, funciona bien cambie page_id = 19 con su número de página:

<?php $the_query = new WP_Query( 'page_id=19' ); ?>

<?php while ($the_query -> have_posts()) : $the_query -> the_post();  ?>

                       <?php the_excerpt(); ?>


     <?php endwhile;?>
    
respondido por el Haitham Shehata 27.12.2014 - 10:13
0

Si estás en el bucle haz esto:

<?php
$my_excerpt = get_the_excerpt();
if ( $my_excerpt != '' ) {
    // Some string manipulation performed
}
echo $my_excerpt; // Outputs the processed value to the page

O si tiene una identificación, obtenga la publicación y luego solicite al miembro post_excerpt var

por ejemplo

$post = get_post( $post_id );
echo $post->post_excerpt;
    
respondido por el Tom J Nowell 04.06.2013 - 16:05
0

Pruebe este código y solo cambie su page_id :

<?php $my_query = new WP_Query('page_id=20');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;?>
 <h3><?php the_title(); ?></h3>
    <div class="text">

        <?php echo wp_trim_words( get_the_content(), 15, '...' ); ?>
 <a href="<?php echo get_page_link(); ?>" class="read-more">Read More</a>
    </div>

 <?php endwhile; ?>
    
respondido por el Jmd Web Solutionss 07.02.2018 - 08:37
0
$post   = get_post( 42 );

$output =  apply_filters( 'the_content', $post->post_content );

echo $output;

de enlace

    
respondido por el João Marcos Santos Teixeira 17.03.2018 - 14:18

Lea otras preguntas en las etiquetas