简体   繁体   English

如何在php中获取wordpress帖子的标题

[英]How to get the title of wordpress post in php

How can i get the title of WordPress post in this php code 我如何在此php代码中获得WordPress帖子的标题

 <?php include("imdb.php");   $imdb = new Imdb(); $movieArray =
 $imdb->getMovieInfo("**.get_the_title().**"); echo '<table
 cellpadding="3" cellspacing="2" border="1" width="80%"
 align="center">'; foreach ($movieArray as $key=>$value){
     $value = is_array($value)?implode("<br />", $value):$value;
     echo '<tr>';
     echo '<th align="left" valign="top">' . strtoupper($key) . '</th><td>' . $value . '</td>';
     echo '</tr>'; } echo '</table>'; ?>

I tried to put ".get_the_title()." 我试图放入".get_the_title()." but don't result the title of current post. 但不会得出当前帖子的标题。

I assume your code is in a wordpress loop, so you just have to use : 我假设您的代码在wordpress循环中,因此您只需要使用:

$imdb->getMovieInfo(get_the_title());

Using $imdb->getMovieInfo("**.get_the_title().**"); 使用$imdb->getMovieInfo("**.get_the_title().**"); don't work since PHP don't handle function inside strings : http://www.php.net/manual/language.types.string.php 由于PHP无法处理字符串内部的函数,因此无法正常工作: http : //www.php.net/manual/language.types.string.php

get_the_title() function requires that you pass it an $id if you are not in the loop . 如果您不在循环中get_the_title()函数要求您传递一个$id If you are in the loop, and want to use the current post's id for getting the title, then you can call the function with out passing anything. 如果您处于循环中,并希望使用当前帖子的ID来获取标题,则可以在不传递任何内容的情况下调用该函数。

See get_the_title , the_loop . 参见get_the_titlethe_loop

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

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