调整Wordpress功能以获取帖子的作者ID


Adjust Wordpress function to grab author ID of post

我为Wordpress使用了一个点系统插件。通过将此代码添加到author.php页面:

<?php cp_displayPoints($authordata->ID); ?>

它将回声X Points。这是各自作者的观点。当我将相同的代码添加到single.php(postpage)时,它会回显已登录用户的点,如果未登录,则返回空白。

如何更改此代码,使其在single.php页面上也能正常运行?这意味着它将呼应该帖子作者的观点

只需在循环中调用get_the_author_meta。

所以,你只需要测试你是否有一个当前登录的用户,如果没有使用post作者。像这样的东西。

<?php
if(!$authordata->ID)
  cp_displayPoints(get_the_author_meta('ID'));
else
  cp_displayPoints($authordata->ID);
?>

编辑:

要只显示文章作者的ID,只需使用

<?php cp_displayPoints(get_the_author_meta('ID')); ?>