简体   繁体   English

如何获得WordPress的职位标题

[英]How to get the title of wordpress post

I know there is a question with similar title but my question is different. 我知道有一个标题相似的问题,但我的问题有所不同。 How can I get the title of wordpress post. 我如何获得wordpress帖子的标题。 I know the_title() returns AND prints the title of the post. 我知道the_title()返回并打印帖子的标题。 But I don't want it to print. 但我不希望它打印。 I just want to take it in a PHP variable that I can use later on. 我只想将其放入一个PHP变量中,以便以后使用。 Anybody knows? 有人知道吗

Look in to the link below which is available in the wordpress docs. 查看下面的链接,该链接在wordpress文档中可用。

This function will return the title of a post for a given post ID. 此函数将返回给定帖子ID的帖子标题。 If the post is protected or private, the word "Protected: " or "Private: " will be prepended to the title. 如果帖子是受保护的或不公开的,则标题前会加上“ Protected:”或“ Private:”一词。 It can be used inside or outside of The Loop. 它可以在The Loop的内部或外部使用。 If used outside the loop an ID must be specified. 如果在循环外部使用,则必须指定一个ID。

Quoted from the link below. 从下面的链接引用。

https://codex.wordpress.org/Function_Reference/get_the_title https://codex.wordpress.org/Function_Reference/get_the_title

Capture it with the ob_ functions: 使用ob_函数捕获它:

ob_start();
the_title()
$title = ob_get_clean();

What this does, is you print it, but only after starting an output buffer, so you print it to that buffer, then get it from the buffer and close the buffer. 它的作用是打印它,但仅在启动输出缓冲区后才将其打印到该缓冲区,然后从缓冲区中获取它并关闭缓冲区。

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

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