Adjust WordPress function to grab author ID of post
我为Wordpress使用了积分系统插件。通过将此代码添加到author.php页面:
1 | <?php cp_displayPoints($authordata->ID); ?> |
它将回显
如何更改此代码,使其也可以在single.php页面上正常运行?这意味着它将与该帖子作者的观点相呼应。
只需从循环内调用get_the_author_meta。
因此,您只需要测试您是否有当前登录的用户(如果不使用帖子作者)。像这样的东西。
1 2 3 4 5 6 | <?php if(!$authordata->ID) cp_displayPoints(get_the_author_meta('ID')); else cp_displayPoints($authordata->ID); ?> |
编辑:
仅显示帖子作者的ID,只需使用
1 | <?php cp_displayPoints(get_the_author_meta('ID')); ?> |