I use a point system plugin for Wordpress. By adding this code to the author.php page:
<?php cp_displayPoints($authordata->ID); ?>
It will echo X Points
. This is the points of that respective author. When I add the same code to single.php (post page), it echos the logged in user's points, and if not logged in, it returns blank.
How can I alter this code so that it will function properly on the single.php page too? This would mean that it would echo the points of the author of that post .
Just call get_the_author_meta from within the loop.
So, you just need to test if you have a currently signed in user, if not use the post author instead. Something like this.
<?php
if(!$authordata->ID)
cp_displayPoints(get_the_author_meta('ID'));
else
cp_displayPoints($authordata->ID);
?>
EDIT:
To display only the post author's ID, just use
<?php cp_displayPoints(get_the_author_meta('ID')); ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.