wordpress模版post.php
时间 : 2023-12-26 01:48:02 声明: : 文章内容来自网络,不保证准确性,请自行甄别信息有效性

最佳答案

下面是一个基本的WordPress模板post.php的示例,请注意这只是一个示例,你可以根据自己的需求进行修改和定制。

```php

<?php

get_header(); // 获取头部

while (have_posts()) {

the_post();

?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<header class="entry-header">

<h1 class="entry-title"><?php the_title(); ?></h1>

<div class="entry-meta">

<span class="posted-on">

<i class="fa fa-clock-o"></i> <?php the_time('F j, Y'); ?>

</span>

<span class="byline">

<i class="fa fa-user"></i> <?php the_author(); ?>

</span>

</div>

</header>

<div class="entry-content">

<?php the_content(); ?>

</div>

<footer class="entry-footer">

<?php

wp_link_pages(array(

'before' => '<div class="page-links"><span class="page-links-title">' . __('Pages:', 'your-theme') . '</span>',

'after' => '</div>',

'link_before' => '<span>',

'link_after' => '</span>',

'pagelink' => '<span class="screen-reader-text">' . __('Page', 'your-theme') . ' </span>%',

'separator' => '<span class="screen-reader-text">, </span>',

));

?>

</footer>

</article>

<?php

if (comments_open() || get_comments_number()) {

comments_template();

}

}

get_footer(); // 获取底部

?>

这个模板文件用于显示单篇文章的内容。在模板中,我们首先使用`get_header()`来获取头部部分,然后使用`while (have_posts()) {...}`循环遍历文章内容。

在循环中,我们使用`the_post()`函数来获取文章内容,然后显示文章的标题、作者、发布日期等信息。接着我们使用`the_content()`函数来显示文章内容。

最后,我们使用`wp_link_pages()`函数来显示文章分页导航,以及使用`comments_template()`函数来显示文章的评论。

最后,我们使用`get_footer()`来获取底部部分。注意,你可以根据自己的需要对模板进行自定义和修改。

其他答案

以下是一个基本的WordPress模板文件post.php的示例:

```php

<?php

/**

* The template for displaying single posts.

*

* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post

*

* @package WordPress

* @subpackage Twenty_Twenty

* @since Twenty Twenty 1.0

*/

get_header();

?>

<main id="primary" class="site-main">

<?php

while (have_posts()) :

the_post();

?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<header class="entry-header">

<?php

if (is_singular()) :

the_title('<h1 class="entry-title">', '</h1>');

else :

the_title('<h2 class="entry-title"><a href="' . esc_url(get_permalink()) . '" rel="bookmark">', '</a></h2>');

endif;

if ('post' === get_post_type()) :

?>

<div class="entry-meta">

<?php

twenty_twenty_posted_by();

twenty_twenty_posted_on();

?>

</div><!-- .entry-meta -->

<?php endif; ?>

</header><!-- .entry-header -->

<?php twenty_twenty_post_thumbnail(); ?>

<div class="entry-content">

<?php

the_content();

wp_link_pages(

array(

'before' => '<div class="page-links">' . __('Pages:', 'twentytwenty'),

'after' => '</div>',

)

);

?>

</div><!-- .entry-content -->

<footer class="entry-footer">

<?php twenty_twenty_entry_footer(); ?>

</footer><!-- .entry-footer -->

</article><!-- #post-<?php the_ID(); ?> -->

<?php

if (is_single()) :

twenty_twenty_post_navigation();

endif;

// If comments are open or we have at least one comment, load up the comment template.

if (comments_open() || get_comments_number()) :

comments_template();

endif;

endwhile; // End of the loop.

?>

</main><!-- #primary -->

<?php get_footer(); ?>

上述代码是WordPress主题Twenty Twenty的post.php文件的示例,用于显示单篇文章的内容。它包含了文章标题、元信息、特色图片、正文内容、分页链接、文章导航和评论模板等内容。你可以根据需要,根据自己的主题进行相应的修改和扩展。