简体   繁体   English

如何在Wordpress的帖子内容中包含帖子标题?

[英]How to include the post title in the post content in wordpress?

If the post title is "concepts" I want the post content to be something like that "in "post title" we care about our client satisfaction by following "post title" high quality policy" so i want the post content include "concepts" and replace it with post title I think wordpress shortcode api can do something like that. 如果帖子标题是“概念”,我希望帖子内容是“在“帖子标题”中的东西”,那么我们会遵循“帖子标题”高质量政策来关注客户满意度,因此我希望帖子内容包括“概念”并将其替换为帖子标题,我认为wordpress shortcode api可以做到这一点。 But i don't know how ? 但是我不知道怎么办?

I don't fully understand your statement. 我不完全理解你的说法。 But I think wordpress hooks can help you do that You can try someting like: 但是我认为wordpress hook可以帮助您做到这一点,您可以尝试以下方式:

function change_post_title ( $post_title ) {
   if ( $post_title ==  'conecpts'  ) {
     $title = 'The new title'; 
     return $title; 
 }
 return $post_title;
}

add_filter('the_title', 'change_post_title');

This will change the post title to "The new post title" if the title is "concepts" 如果标题是“ concepts”,这会将帖子标题更改为“新帖子标题”

Please make your question clear as to what is the problem and what you want to accomplish. 请明确您的问题是什么,您要完成什么。

In your post content you will need add a shortcode where you want the title printed, int eh shortcode example below you will use [post_title] . 在您的帖子内容中,您需要在要打印标题的位置添加一个简短代码,下面的简短代码示例将使用[post_title]

function post_title_shortcode( $atts ){
     extract( shortcode_atts( array(
        'post_id' => get_the_ID()
        ), $atts ) );

     return get_the_title( $post_id );
}
add_shortcode( 'post_title', 'post_title_shortcode' );

With that shortcode you can pass the post id so that if you want to get the title of another post you could do use the shortcode [bartag post_id="123"] where 123 is the post id of the title you want to show. 使用该简码,您可以传递帖子ID,这样,如果要获取其他帖子的标题,则可以使用简码[bartag post_id="123"] ,其中123是要显示的标题的帖子ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM