- This topic has 63 replies, 3 voices, and was last updated 4 years, 8 months ago by Tom.
-
AuthorPosts
-
June 6, 2019 at 3:13 am #921376culpable
Hiya GP Support,
I’m wondering what’s the best way for me to go about editing the Author Archive pages?
Note that I’ve currently added this code to my pages as per the GP Press example site to add Author boxes:
add_filter( 'generate_post_author_output', function() { printf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" %5$s>%1$s <a class="url fn n" href="%2$s" title="%3$s" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span>', __( 'by', 'generatepress' ), esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), /* translators: 1: Author name */ esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ), esc_html( get_the_author() ), generate_get_microdata( 'post-author' ) ) ); } );
I’d like to make some adjustments to the Author pages so that they only show the most recent 3 posts of the author. I’d also like to add custom social buttons (Linkedin, Twitter, etc) to the page.
What is the best way for me to go about editing these author archive pages?
Thank you for your help 🙂
June 6, 2019 at 4:31 am #921435DavidStaffCustomer SupportHi there,
1. You can limit number of posts on author page with this function:
function set_author_archive_limit( $query ) { if ( is_admin() || ! $query->is_main_query() ) return; if ( is_author() ) { $query->set( 'posts_per_page', 3 ); return; } } add_action( 'pre_get_posts', 'set_author_archive_limit', 1 );
2. To make amends to the author page you would need either a plugin or child theme and create your own author page. This guide provides both options:
https://www.wpbeginner.com/wp-themes/how-to-add-a-custom-author-profile-page-to-your-wordpress/
An alternative route would be to register some new fields in your user Profile with this function:
function thewebsitedev_user_social_links( $user_contact ) { /* Add user contact methods */ $user_contact['facebook'] = __('Facebook Link', 'topaz'); $user_contact['twitter'] = __('Twitter Link', 'topaz'); $user_contact['dribbble'] = __('Dribbble Link', 'topaz'); $user_contact['pinterest'] = __('Pinterest Link', 'topaz'); $user_contact['linkedin'] = __('LinkedIn Link', 'topaz'); $user_contact['googleplus'] = __('Google+ Link', 'topaz'); return $user_contact; } add_filter('user_contactmethods', 'thewebsitedev_user_social_links');
Source: https://thewebsitedev.com/social-links-wordpress-user-profile/
Then hook the code they provide for displaying them using the hook element:
https://docs.generatepress.com/article/hooks-element-overview/
June 7, 2019 at 6:40 am #922573culpableThank you for your prompt reply and excellent suggestions David
To clarify my previous comment: I meant that the author page should show the most recent 3 posts for the author with no other posts shown (i.e. right now it’s showing 3 *per page*. I don’t want all the posts to show (i.e. there shouldn’t be any pagination).
Thank you for your assistance David
June 7, 2019 at 8:44 am #922766DavidStaffCustomer SupportTry switching where the code says
posts_per_page
forshowposts
June 7, 2019 at 5:27 pm #923026culpableSame result (I cleared the cache, and changed the number of posts from 3->5 to make sure it wasn’t a caching issue)
June 8, 2019 at 3:57 am #923211DavidStaffCustomer SupportWell this one got me puzzled – the original code works on my tests, not sure if that’s correct or not…..
Would hiding the Nav on author pages with some CSS be ok, if so this:
.archive.author #nav-below { display: none; }
June 8, 2019 at 5:20 am #923255culpableHiding the Nav isn’t a good solution for me as part of what’s driving this is the desire to index author pages, without indexing 30 different pages via the pagination intrinsic to the author archives.
If it works in your testing, then maybe the difference falls on the distinction between pages vs. posts? I don’t use wordpress “posts”, only wordpress “pages”. I failed to mention the difference until now as your previous change seemed to successfully alter the number of “pages” showing in the author archives, so I didn’t think it was relevant. For reference, this is the code I’m using to show pages on author archives:
add_action( 'pre_get_posts', function( $query ) { if ( ! $query->is_main_query() || is_admin() ) { return; } if ( $query->is_author ) { $query->set( 'post_type', array( 'post', 'page' ) ); $query->set( 'post__not_in', array(6539329,5533747,320,25753) ); } } );
(The “post__not_in” being used to exclude pages I do not wish to be included in the archives)
Are you able to confirm that your suggested code works as intended for both pages and posts? 🙂
June 8, 2019 at 9:09 am #923472TomLead DeveloperLead DeveloperWhat if we just disable pagination on author archives?:
add_filter( 'generate_show_post_navigation', function( $show ) { if ( is_author() ) { $show = false; } return $show; } );
June 8, 2019 at 7:07 pm #923704culpableThank you for the code Tom.
This removed the pagination, but the pages are still available at
/author/*author name*/page/3
This doesn’t quite solve the issue as I still can’t see the way for me to index
/author/*author name*/
whilst deindexing all the other paginated pages.June 9, 2019 at 7:40 am #924072TomLead DeveloperLead DeveloperLet’s try replacing David’s code with this:
add_action( 'pre_get_posts', function( $query ) { if ( is_admin() || ! $query->is_main_query() ) { return; } if ( is_author() ) { $query->set( 'posts_per_page', 3 ); $query->set( 'no_found_rows', true ); } } );
Let me know 🙂
June 9, 2019 at 2:19 pm #924300culpableThank you for the code Tom.
Unfortunately, this doesn’t seem to be working either. Whether isolated or combined with the previous code to disable pagination, the pages are still available at
/author/*author name*/page/2
/author/*author name*/page/3
etc.Again I toggled the “showposts” 3->5 to make sure it was working. I also hard cleared the cache. Any other suggestions? 🙂
June 9, 2019 at 2:53 pm #924317TomLead DeveloperLead DeveloperI just made an adjustment here: https://generatepress.com/forums/topic/custom-author-archive-pages/#post-924072
Let me know 🙂
June 9, 2019 at 3:02 pm #924322culpableWell – it got rid of the pagination!
But.. it put all 1000 pages (by the Author) on the same author archive page.
It doesn’t seem to be respecting the
$query->set( 'showposts', 3 );
June 9, 2019 at 3:08 pm #924325TomLead DeveloperLead DeveloperGetting there slowly.. Can you try again?: https://generatepress.com/forums/topic/custom-author-archive-pages/#post-924072
June 10, 2019 at 12:19 am #924506culpableThank you Tom – still showing the same result as the previous code though :\
-
AuthorPosts
- You must be logged in to reply to this topic.