-
AuthorPosts
-
November 29, 2023 at 9:42 pm #1426739
Hello,
is there a way to set that more posts from the same author are shown below a post, with a large image and a title, category, date and author
I would also like to ask if I can add date and author to blog posts grid layout next to the category
I would also like to make a sidebar widget where id display info about the author and an option to subscribe. Is there a way to pull the author image to a widget and the number of their posts?
Best regards
November 30, 2023 at 3:43 am #1426751Hey nebuddlho,
Thank you for the inquiry.
If you’re using the Advanced Layout Builder, you can insert a Blog Posts element in the post, then add this filter in the functions.php file to display other posts from the same author.
add_filter("avia_post_slide_query", function($query) { global $post; if(is_singular('post')) { $author_id = $post->post_author; $query["author__in"] = array($author_id) } return $query; }, 10, 1);
To display the category list and author info, please go to the Enfold > Blog Layout > Blog Meta Elements section and toggle the elements as you wish.
Best regards,
IsmaelNovember 30, 2023 at 2:43 pm #1426803Hello, I’m not using the ALB for posts. Currently there’s no posts from author, just “You may be interested in” and small thumbs.
Regarding the author info/date I have it enabled in blog layout, but there’s still only the category in the blog posts grid layout element on the homepage.
December 2, 2023 at 4:30 pm #1426965Hi,
Thanks for your patience and the link to your testing site, I saw that you only have one post and one author, so I created a few more posts and another author to test the code for the display_author_posts element at the bottom of your posts and was having some success, but unfortunately in one of my edits to the code I made an error ans crashed the site, please include FTP access, so I can fix my error in the child theme functions.php and continue with my tests.
Unfortunately the theme editor is not forgiving and when you make an error you also lose access the editor.Best regards,
MikeDecember 2, 2023 at 5:45 pm #1426969Hi,
I tested some more on my demo site and the following code seems to work well, so you can try replacing the code that I added to your child theme functions.php with this:function display_author_posts() { if (is_single()) { global $post; $author_id = $post->post_author; $num_posts_to_display = 4; // adjust to the number of posts to display per row any number higher than 3 $items_per_row = 4; // adjust to the number of items per row either 3, 4, or 5 if (isset($_GET['items_per_row'])) { $items_per_row = intval($_GET['items_per_row']); $items_per_row = in_array($items_per_row, array(3, 4, 5)) ? $items_per_row : 3; } $args = array( 'author' => $author_id, 'post__not_in' => array($post->ID), 'posts_per_page' => $num_posts_to_display, ); $author_query = new WP_Query($args); if ($author_query->have_posts()) { $post_counter = 0; echo '<div class="author-posts container">'; echo '<h2>Other Articles by ' . get_the_author_meta('display_name', $author_id) . '</h2>'; echo '<div class="article-grid">'; while ($author_query->have_posts()) { $author_query->the_post(); $post_counter++; if ($items_per_row === 4) { $item_class = 'av_one_fourth'; } elseif ($items_per_row === 5) { $item_class = 'av_one_fifth'; } else { $item_class = 'av_one_third'; } $first_class = ($post_counter % $items_per_row === 1) ? ' first' : ''; echo '<div class="article-item ' . $item_class . ' flex_column' . $first_class . '">'; echo '<a href="' . get_permalink() . '">'; echo '<img src="' . get_the_post_thumbnail_url($post->ID) . '" alt="' . get_the_title() . '" />'; echo '</a>'; echo '<h3><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>'; echo '<span class="post-meta-infos">'; echo '<time class="date-container minor-meta updated"> ' . get_the_date() . '</time>'; echo '<span class="blog-categories minor-meta"> / in ' . get_the_category_list(', ') . '</span>'; echo '<span class="blog-author minor-meta"> / by <a href="' . get_author_posts_url($author_id) . '">' . get_the_author() . '</a></span>'; echo '</span>'; echo '</div>'; if ($post_counter % $items_per_row === 0) { echo '<div style="clear:both;"></div>'; } } echo '</div>'; echo '</div>'; } wp_reset_postdata(); } } add_filter('ava_before_footer', 'display_author_posts');
it adds the “Other Articles by [author]” to the bottom of the posts just above the footer after the “related posts” and the comment form, this is the expected result:
in the code above you will note two options:
$num_posts_to_display = 4; // adjust to the number of posts to display per row any number higher than 3
$items_per_row = 4; // adjust to the number of items per row either 3, 4, or 5
the $num_posts_to_display is the total posts from the author you want to show, if it is the same as the second option you will see just one row, if it use double you wil see two rows, etc.
the $items_per_row is how many items in each row, you can choose only 3, 4, or 5 due to the required classes needed for the built-in theme css to create the grid. I wanted this function to use the theme classes and layout so it is consistent with the rest of the theme.Best regards,
MikeDecember 4, 2023 at 3:27 pm #1427141Hello, thank you for the replies
Unfortunately I’ve attached the wrong details for the development site, I will fix the previous one, and sending the proper credentials now
December 4, 2023 at 6:09 pm #1427157Hi,
Ok, I see that the theme editor is disabled so I can’t test the above solution, please give it a try.
If it doesn’t work then include FTP access in the Private Content area.Best regards,
MikeDecember 12, 2023 at 3:20 pm #1427876Hello,
I have one more question about this function please, is it possible that the content is not below the widget area? sometimes the banners in my widget are too long, and the related posts are then too far below. Thank you in advance.
December 12, 2023 at 5:52 pm #1427898Hi,
Unfortunately, I was only able to add this reliably after the content and above the footer, if your sidebar widget area is very long it will push it down.
Instead of adding this automatically we could change it into a shortcode and you could manually add it into your posts under your content and then it would be before the “related posts” and comment form, and the sidebar would not push it down.
Do you mind manually adding a shortcode into each of your posts?Best regards,
MikeDecember 12, 2023 at 5:58 pm #1427899Unfortunately, there are too many posts on the page. Is there a chance to add the shortcode somewhere inside the theme files after the comments?
December 12, 2023 at 6:23 pm #1427903Hi,
Unfortunately not, the solution above was the closest. I might be able to move the element after the page loads with javascript, are all of your posts using the same layout?
Please include a link to couple of your posts, one that looks good and one that doesn’t and one that is typically of all of your posts.
Then I will see where I can move the element to with javascript and let you know. Do you prefer it after the comments and before the related posts?
Please leave the function above in place so the “Other Articles by [author]” will show.Best regards,
MikeDecember 16, 2023 at 1:52 pm #1428265Hello,
I am sending links of posts and login details again. The default related posts are hidden, and probably after the comments.Thank you for your help
December 16, 2023 at 3:29 pm #1428268Hi,
Unfortunately this author element is behaving as a full width element so moving it breaks the sidebar, so we won’t be able to move it.
So in the few cases that the blog post is shorter than your sidebar you will have a gap, unless you make your sidebar shorter.Best regards,
MikeDecember 18, 2023 at 10:16 am #1428382Okay, I understand. You can close the topic
-
AuthorPosts
- The topic ‘Same author posts’ is closed to new replies.