方法一:
<?php
$args = array(
'p' => 6198, // ID of a page, post, or custom type
'post_type' => 'post',
'posts_per_page' => 1
);
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php endwhile; ?> <!-- end of the loop -->
<?php wp_reset_postdata(); ?>
<?php else : ?>
<?php endif; ?>
方法二:
<?php $post_id = 2408;
$postArray = get_post($post_id, ARRAY_A);
$title = $postArray['post_title'];
$url = $postArray['guid'];
echo "<a href=" . $url. ">" .$title. "</a>" ;
?>
<?php
$args = array(
'p' => 6198, // ID of a page, post, or custom type
'post_type' => 'post',
'posts_per_page' => 1
);
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php endwhile; ?> <!-- end of the loop -->
<?php wp_reset_postdata(); ?>
<?php else : ?>
<?php endif; ?>
方法二:
<?php $post_id = 2408;
$postArray = get_post($post_id, ARRAY_A);
$title = $postArray['post_title'];
$url = $postArray['guid'];
echo "<a href=" . $url. ">" .$title. "</a>" ;
?>