在Wordpress帖子的内容中显示[post_title]?

时间:2017-06-01 18:04:35

标签: wordpress

只想展示Wordpress帖子的标题。我尝试过没有成功。对此很新。

2 个答案:

答案 0 :(得分:0)

你可以试试这个,我希望这会对你有帮助。

<?php if ( have_posts() ) : ?>

<?php while ( have_posts() ) : the_post(); ?>

    <h2><?php the_title(); ?></h2>

<?php endwhile; ?>

如果你想添加自定义帖子类型,那么你需要添加WP_Query();函数来获取如下数据:

<?php

// The Query
$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) {
    echo '<ul>';
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
    echo '</ul>';
    /* Restore original Post Data */
    wp_reset_postdata();
} else {
    // no posts found
}

答案 1 :(得分:0)

用于在特定页面中显示帖子标题,您可以写下:

<?php get_the_title($post_id);?>

进入该页面的模板文件,或者您可以在模板文件夹中创建自定义文件并添加以下代码:

<?php if (is_page( 'Page Title' ) ): get_the_title($post_id); endif; ?>

并将其包含在您的所有页面中..您可以在if语句中使用OR条件检查多个页面。

相关问题