Obtenir le contenu d'une page spécifique (par ID)
7 réponses
- votes
-
- 2013-06-04
<?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 ); ?>
<?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 ); ?>
-
- 2015-11-16
Et voilà!
<?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; ?>
Here you go !
<?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; ?>
-
Veuillezexpliquer ce quefait le codeet commentil répond à la question.Certains utilisateurspeuventne pas comprendre le code sans unepetite explication.Please, explain what the code does and how it answers the question. Some users may not understand the code without a little explanation.
- 5
- 2015-11-16
- cybmeta
-
J'aime vraiment lafaçon dont vous avez ajouté lefiltre `the_content`.+1pour ça.I really like the way you added `the_content` filter. +1 for that.
- 1
- 2016-05-04
- Mohammad Mursaleen
-
Fonctionnetrèsbien!Works beautiful!
- 0
- 2019-07-19
- Charles Xavier
-
Quefait le str_replace?What does the str_replace do?
- 0
- 2020-04-30
- netAction
-
- 2018-03-17
$post = get_post( 42 ); $output = apply_filters( 'the_content', $post->post_content ); echo $output;
de https://developer.wordpress.org/reference/functions/get_post/
$post = get_post( 42 ); $output = apply_filters( 'the_content', $post->post_content ); echo $output;
from https://developer.wordpress.org/reference/functions/get_post/
-
- 2014-12-27
vouspouvez utiliser ce code,ilfonctionnebien changezpage_id=19par votrenuméro depage:
<?php $the_query = new WP_Query( 'page_id=19' ); ?> <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> <?php the_excerpt(); ?> <?php endwhile;?>
you can use this code it is work fine change page_id=19 with your page number:
<?php $the_query = new WP_Query( 'page_id=19' ); ?> <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> <?php the_excerpt(); ?> <?php endwhile;?>
-
Bienvenue sur ce site.Il semble que ce soit votrepremière réponse.Ilesttoujoursbon d'expliquerpourquoiet comment votre réponse résout leproblème.Wellcome to this site. It seems that thisis your first answer. A explanation of why and how your answer solves the problem is always good.
- 1
- 2014-12-27
- cybmeta
-
- 2013-06-04
Si vous êtes dans laboucle,procédez comme suit:
<?php $my_excerpt = get_the_excerpt(); if ( $my_excerpt != '' ) { // Some string manipulation performed } echo $my_excerpt; // Outputs the processed value to the page
Ou si vous avez unidentifiant,récupérez lemessagepuispoursuivez lemembre depost_excerpt var
Parexemple
$post = get_post( $post_id ); echo $post->post_excerpt;
If you're in the loop do this:
<?php $my_excerpt = get_the_excerpt(); if ( $my_excerpt != '' ) { // Some string manipulation performed } echo $my_excerpt; // Outputs the processed value to the page
Or if you have an ID, get the post then sue the post_excerpt member var
e.g.
$post = get_post( $post_id ); echo $post->post_excerpt;
-
- 2018-02-07
Essayez ce codeet changez simplement votre
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; ?>
Try this code and just change your
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; ?>
-
- 2020-02-06
Pour les accros de la doublure commemoi.Modifiez 69par votreidentifiant depage.
<?= apply_filters('the_content', get_post(69)->post_content); ?>
For one liner addicts like me. Change 69 by your page ID.
<?= apply_filters('the_content', get_post(69)->post_content); ?>
J'ai créé lemodèle depage d'accueil suivant:
À laplace de cesgrandsblocs Lorem Ipsum ,je dois afficher un "extrait" d'unepage spécifiquepour remplir cette case (un certainnombre de caractères).
Commentpuis-je obtenir le contenu d'unepage auformat String afin depouvoir le répéteret le réduire à un certainnombre de caractères?