我完成了我的Wordpress网站的所有页面。
例如。
标题1:如何在Wordpress上建立一个网站
标题2:如何保护WP网站
现在我想把这一行添加到底部的所有页面:
"如果你对[页面标题]有任何问题,请在下面留言!"
我期望的结果应该是:
第1页内容:
步骤1
步骤2
如果你对如何在Wordpress上建立一个网站有任何问题,请在下面留言!
第2页内容
步骤1
步骤2
如果您对如何保护WP网站有任何疑问,请在下面发表评论!
我该怎么做呢?
您可以通过the_content
过滤器更改页面内容看看下面的代码
add_filter( 'the_content', 'add_bottom_content' );
function add_bottom_content( $content ) {
$content .= "If you have any question on ".get_the_title().", please give a comment below!";
return $content;
}
您可以使用wp函数the_title()
the_title(string $before = ", string $after = ", bool $echo = true)
显示或检索具有可选内容的当前文章标题。
参数#参数
之前美元后美元(string) (Optional) Content to prepend to the title. Default value: ''
(string) (Optional) Content to append to the title. Default value: ''
美元回声
(bool) (Optional) default to true.Whether to display or return.
Default value: true
。:
the_title("If you have any question on ", ", please give a comment below!")
你可以在你的页面模板中添加一些php代码。
我以二十六主题为例。在wp-content/主题/twentysixteen/模板/content-page.php
在entry-contentdiv中添加If you have any question on <?php the_title(); ?>, please give a comment below!
。
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->
<?php twentysixteen_post_thumbnail(); ?>
<div class="entry-content">
<?php
the_content();
wp_link_pages( array(
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentysixteen' ) . '</span>',
'after' => '</div>',
'link_before' => '<span>',
'link_after' => '</span>',
'pagelink' => '<span class="screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>%',
'separator' => '<span class="screen-reader-text">, </span>',
) );
?>
If you have any question on <?php the_title(); ?>, please give a comment below!
</div><!-- .entry-content -->
<?php
edit_post_link(
sprintf(
/* translators: %s: Name of current post */
__( 'Edit<span class="screen-reader-text"> "%s"</span>', 'twentysixteen' ),
get_the_title()
),
'<footer class="entry-footer"><span class="edit-link">',
'</span></footer><!-- .entry-footer -->'
);
?>
</article><!-- #post-## -->