Back to Blog Front Editor Support

October-Junkie
October-Junkie

Hi Kurt, great plugin!!

I was wondering if there is a way to loop the authors. I'm trying to set up a page where I can display the author name/ bio/ and all the posts he/she has written. At the same time only delegated users/authors would have such profile page. Thank you!

KurtJensen
KurtJensen

How about this page and code as a starting point:

title = "Authors"
url = "/authors"
is_hidden = 0
==
<?php
function onStart()
{
    $user_ids = FireUnion\BlogFront\Models\Author::lists('user_id');

    $this['authors'] = RainLab\User\Models\User::whereIn('id',$user_ids)->get();
}
?>
==
<!DOCTYPE html>
<html>
<head>
<title>HS</title>
</head>
<body>
{% for author in authors %} 
{{author.name }} <br>
{% endfor %}
</body>
</html>

F.Y.I. - I am the plugin author for Fire Union Development. Thanks for using my plugin. ;-)

Last updated

October-Junkie
October-Junkie

Thank's Kurt! Much appreciated, I also have your Profile plugin, keep up the awesome work!

October-Junkie
October-Junkie

Sorry still having a little trouble. Trying to achieve following:

  1. Display authors along with 3 most recent posts from each author and then paginate by authors.

  2. On a separate page display authors details ( from your Profile plugin :) ) along with all the authors posts/paginate. I've tried dd($this['eprofiles']); but the return doesn't seem to have the variables from the Person/Professional section on the backend. Also having trouble linking to authors details page with slug, it only appears to work with id: "author/{{ author.id }}" . The author name would be ideal for SEO, would I have to extend the plugin?

Sorry for my ignorance, I'm a newbie, any help is greatly appreciated.

Here is the page for No.1. Authors with 3 most recent posts: Current method returns all posts for each, no relation to author.

 title = "Author Posts"
 url = "/authors-posts/:id"
 layout = "default"
 is_hidden = 0
 [session]
 security = "all"
 ==
 <?php

 function onStart(){

 $user_ids = FireUnion\BlogFront\Models\Author::lists('user_id');

 $this['posts'] = Rainlab\Blog\Models\Post::all();

 $this['authors'] = RainLab\User\Models\User::whereIn('id',$user_ids)- 
 >paginate(6);

 }

 ?>
 ==
 <section>
 <div class="row">
 <div class="col s12 m10 offset-m1">

 {% for author in authors %} 
 <div class="valign-wrapper">
 <div class="row"> 
 <div class="col s12 m3"> 
 <a href="author/{{ author.id }}"> 
 <img src="{{author.avatar.path}}" alt="" class="circle responsive-img" >
 <h5 class="white-text center"> {{ author.name }}</h5>
 </a>
 </div>

 {% for post in posts %} 
 <div class="col s12 m2"> 
 <div class="card grey darken-3">
<a href="channel/{{ post.slug }}"> 
{% for image in post.featured_images|slice(0,1) %} 
<div class="card-image waves-effect waves-block waves-light">
<img src="{{image.path}}" height="150px"></div> 
{% endfor %} 
 <div class="card-title">{{post.title}}</div>
 </a>
 </div>
 </div>

 {% endfor %}

 </div>
 </div>

 {% endfor %}

 </div>
 </div>
 </section>

 <div class="row center">
 {{ authors.render|raw }}
 </div>

I've tried the following variations:

$this['posts'] = Rainlab\Blog\Models\Post::whereIn('title',$user_ids)->take(3);

$this ['posts'] = RainLab\Blog\Models\Post::where('id','$authors')->take(3);
 foreach ($posts as $user_id => $author) {
}   

and with twig:

  {% for post in author.posts %}
  {{ post.title }}
  {% endfor %}

  {% for author, post in posts %}
  {{ post.title }}
  {% endfor %}

===

Authors details page, No.2. I'm in the dark here, nothing renders.

 title = "author"
 url = "/author/:id"
 layout = "alpha"
 is_hidden = 0
 ==
 <?php

 function onStart(){

 $user_ids = FireUnion\BlogFront\Models\Author::lists('user_id');

 $this['author'] = FireUnion\BlogFront\Models\Author::where('id', '=', $this- 
  >param('id'))->first();

 $this['authors'] = RainLab\User\Models\User::whereIn('id',$user_ids)- 
 >paginate(8);

 }

 ?>
 ==
 {% if author %}

 {{ author.name }} 
 {{ author.aboutme }} 
 {{ author.position }} 
 {{ author.hobbies }} 
 {{ author.acomplishments }} 

 <section>
 <div class="row">
 <div class="col s12 m10 offset-m1">
<div class="col s12"> 

 {% for post in posts %}

 <div class="col s12 m4">
 <div class="card medium">
 <div class="card-image">
 <a href="{{ post.url }}">

 {% for image in post.featured_images|slice(0,1) %}

 <img class="responsive-img" src="{{image.path}}">

 {% endfor %} 

 <span class="card-title">
 <h4> {{ post.title }} </h4>
</span>
 </a>
 </div>

 <div class="card-content">
 <div class="row">
 <div class="col s12">
 <span class="tile">
 {{ post.author.name }} 
 </span>
 <br>
<span class="tile">
{{ post.published_at|date('M d, Y') }}
</span>
 </div>
 </div>
<div class="card-action grey darken-2">
 <div class="center"> 

 {% if post.categories.count %} {% endif %}
 {% for category in post.categories %}

 <a 
  href="{{ category.url }}">
 <i class="fas fa-tag"></i>
 {{ category.name }}
 </a>

 {% if not loop.last %}{% endif %}
 {% endfor %}

 </div>
 </div>
</div> 
 </div> 
 </div> 

 {% endfor %}

 </div>
 </div>
 </div>
 </section>

 <div class="row center">
 {{ authors.render|raw }}
 </div>

 {% else %}

 Oops nothing here.

 {% endif %}

1-4 of 4