ดึงโพสท์ wordpress เอามาโชว์
<?php
$post_id = 26;
$queried_post = get_post($post_id);
$title = $queried_post->post_title;
echo $title;
echo $queried_post->post_content;
?>
วิธี1 <?php $post_id = 26; $queried_post = get_post($post_id); $title = $queried_post->post_title; echo $title; echo $queried_post->post_content; ?> วิธี2 <?php $post_id = 26; $queried_post = get_post($post_id); ?> <h2><?php echo $queried_post->post_title; ?></h2> <?php echo $queried_post->post_content; ?> วิธี3 <?php $thePostIdArray = array("28","74", "82", "92"); ?> <?php $limit = 4 ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); $counter++; ?> <?php if ( $counter < $limit + 1 ): ?> <div class="post" id="post-<?php the_ID(); ?>"> <?php $post_id = $thePostIdArray[$counter-1]; ?> <?php $queried_post = get_post($post_id); ?> <h2><?php echo $queried_post->post_title; ?></h2> </div> <?php endif; ?> <?php endwhile; ?> <?php endif; ?>
หลายโพสท์ excerpt <?php foreach ( $posts as $post ) : ?> <li> <a href="<?php echo esc_url( get_permalink( $post->ID ) ); ?>"><?php echo esc_html( $post->post_title ); ?></a>: <?php if ( empty( $post->post_excerpt ) ) : ?> <?php echo wp_kses_post( wp_trim_words( $post->post_content, 20 ) ); ?> <?php else : ?> <?php echo wp_kses_post( $post->post_excerpt ); ?> <?php endif; ?> </li> <?php endforeach; ?>
โพสแรก
<?php
$i = 1;
if( have_posts() ) {
while( have_posts() ) {
the_post();
if( 1 == $i ) {
the_excerpt();
}
// the rest of your loop
$i++;
}
}
?>