Fetch data from a specific author

Hi,
Is there a quick way to fetch the data from a specific author in all pages?
Thanks in advance

Not quite sure if I understand your question correctly. Is the author a Kirby user? And do you want to get the data from that user on the page where the user is stored as the author?

Sorry, yes, a Kirby user.
I would like to use the data of a specific user. For example:

<?php if($user = $page->author()->toUser()): ?>
<div class="div">
  <h3><?= $user->name() ?></h3>
  <?= $user->bio()->kt() ?>
</div>
<?php endif ?>

And that doesn’t work? Even though you have an author field in your page?

I think I explained myself wrongly, my fault.

In the footer for example it doesn’t work:

  <div class="footer-top">
    
    <?php if($user = $page->author()->toUser()): ?>

    <div class="footer-socials">
      <h4>Seguimi su:</h4>
      <a href="<?php echo $user->facebook() ?>"></a>
      <a href="<?php echo $user->twitter() ?>"></a>
      <a href="<?php echo $user->linkedin() ?>"></a>
    </div><!-- /footer-socials -->

    <div class="footer-info">
      <a href="mailto:<?php echo $user->email() ?>"><?php echo $user->email() ?></a>
    </div><!-- /footer-info -->

    <?php endif ?>
    
  </div><!-- /footer-top -->

The question is which user do you want to get? A specific user by name?

$page->author()->toUser()

tries to convert the content of an author field on the current page to a user object. If the current page doesn’t have such an author field, this will not return anything.

You can get a specific Kirby user (not author) by email:

if ($user = $kirby->user('you@me.com')) {
  // do something;
}
1 Like

Perfect, it works, very simple :slight_smile:

  <div class="footer-top">
    
    <?php $user = $kirby->user('twSPuJU7') ?>

    <div class="footer-socials">
      <h4>Seguimi su:</h4>
      <a href="<?php echo $user->facebook() ?>"></a>
      <a href="<?php echo $user->twitter() ?>"></a>
      <a href="<?php echo $user->linkedin() ?>"></a>
    </div><!-- /footer-socials -->

    <div class="footer-info">
      <a href="mailto:<?php echo $user->email() ?>"><?php echo $user->email() ?></a>
    </div><!-- /footer-info -->
    
  </div><!-- /footer-top -->

Thank you Sonja.

1 Like