Frage

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.

War es hilfreich?

Lösung

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')); ?>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top