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

问题描述:

只是想显示一个WordPress的帖子的标题。我试过没有成功。这很新鲜。在WordPress内容中显示[post_title]帖子?

+0

显示你试过的代码和错误是什么? –

+0

对不起,包含原始文章中的代码,但没有显示。我尝试过(没有括号): [] – bigtree53

+0

你可以尝试把它放在你的单个PHP或内容循环/单(loop.php,content.php)..没有$ post_id –

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

<?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 
} 

在特定网页上显示文章标题任你可以这样写:

<?php get_the_title($post_id);?>

到该网页的模板文件,也CA n请在模板文件夹中的自定义文件,并添加以下代码:

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

,包括这对所有网页..你可以通过检查多个页面或if语句条件的。