- This topic has 7 replies, 3 voices, and was last updated 3 years, 2 months ago by Elvin.
-
AuthorPosts
-
January 25, 2021 at 8:47 am #1633044Tom
Hi, I had a look at the earlier posts on custom author archive pages in the GP forum and they seem to recommend (if I understand it correctly) replacing the link to the author archive with a custom link.
So, instead of default “domain/author/authorname”, use a custom URL like “domain/authorname”, and then disable the author archive page with Yoast/RankMath. Here: https://generatepress.com/forums/topic/custom-autor-page/
Is there a way to preserve the default URL path “domain/author/authorname” but customize it? In particular, I would like to disable the pagination of all posts written by the author (I just want one page with a few posts) and include a biography with an avatar photo in the center of the page.
I include a reference page in the private info.
Thanks,
TomJanuary 25, 2021 at 10:49 am #1633181YingStaffCustomer SupportHi Tom,
If you just want to hide the pagination of this author’s posts, try this CSS:
.author-tom-qiao .paging-navigation { display: none; }
If you’d apply this to all authors, replace
.author-tom-qiao
with.author
For adding a gravatar, try to add
<img src="your-image-link">
to the header elements.Let me know 🙂
January 26, 2021 at 11:41 am #1634706TomThanks, Ying. That helped remove the paginated pages successfully.
I’d like to customize the author archive page a bit more. Based on the options in Customizer -> Layout -> Blog, it appears the author archive page is affected by the settings for archive pages. How can I make changes to the layout/design of only the author archive page?
Seems this was asked before in the past: https://generatepress.com/forums/topic/create-a-separate-author-php-for-our-child-themes/
I am not a developer so would like to avoid editing .php files if possible. Is using hooks an option to add what I want into the author archive page?
Thank you,
TomJanuary 26, 2021 at 6:39 pm #1634991ElvinStaffCustomer SupportHi there,
Is there a way to preserve the default URL path “domain/author/authorname” but customize it? …
This plugin can help you set the permalink for your author links
https://wordpress.org/plugins/edit-author-slug/…In particular, I would like to disable the pagination of all posts written by the author (I just want one page with a few posts)…
To add an alternative Ying’s solution:
In case you want to control the query for your author archive pages, you can use
pre_get_posts
.This PHP snippet should disable pagination on author archive pages.
add_action( 'pre_get_posts', 'disable_pagination_on_author_archive' ); function disable_pagination_on_author_archive( $query ) { if ( is_author() ){ $query->set( 'posts_per_page', '-1' ); } }
This is just a sample of what it can do. You can even change how many posts are displayed if you wish to do so.
…and include a biography with an avatar photo in the center of the page.
I’m not exactly sure how your avatar photo and biography are stored so I’m not sure what PHP writeup to give you but If you know how to fetch their values, You can use a Hook Element with hook set to where you want them to appear and set their display rule to “Author Archives” so they only display on author archive pages.
Here’s a hook visual guide to give you an idea.
https://docs.generatepress.com/article/hooks-visual-guide/I’d like to customize the author archive page a bit more. Based on the options in Customizer -> Layout -> Blog, it appears the author archive page is affected by the settings for archive pages. How can I make changes to the layout/design of only the author archive page?
You can filter the blog/archive settings using this filter.
https://docs.generatepress.com/article/option_generate_blog_settings/Say, for example, you want infinite scroll on author archive page only, you can do this:
add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' ); function lh_custom_search_results_page_settings( $options ) { if ( is_author() ) { $options['infinite_scroll'] = true; $options['infinite_scroll_button'] = true; } return $options; }
January 27, 2021 at 9:47 am #1635963TomThanks very much, Elvin.
Re: the PHP snippet, yes it’s working to set a custom number of posts per page. However, it seems like I still need Ying’s CSS code to disable pagination from showing up, as the pagination came back when I removed that CSS. Just checking – is the PHP supposed to disable pagination as well?
Re: the hooks, this is exactly what I was thinking of, thanks! Any way to disable the default title and biography on the author archive page? (because I am using hooks to insert my custom ones) See here: https://drive.google.com/file/d/1gLFU8nsvihb6A1DGRhCDOXXSegXSMUq-/view?usp=sharing
Understood about the filter. I’ll keep that in mind.
Thanks,
TomJanuary 27, 2021 at 6:08 pm #1636303ElvinStaffCustomer SupportRe: the PHP snippet, yes it’s working to set a custom number of posts per page. However, it seems like I still need Ying’s CSS code to disable pagination from showing up, as the pagination came back when I removed that CSS. Just checking – is the PHP supposed to disable pagination as well?
Yep but I missed a few details. This one should work.
function wpse_disable_pagination( $query ) { if( $query->is_author() ) { $query->set( 'posts_per_page', '-1' ); } } add_action( 'pre_get_posts', 'wpse_disable_pagination' );
Re: the hooks, this is exactly what I was thinking of, thanks! Any way to disable the default title and biography on the author archive page? (because I am using hooks to insert my custom ones) See here:
The image is added on one of the default functions as shown here:
It’s added along with the author archive title (the author’s name) but you can use the
get_the_archive_title
to change that.Example: (this only returns the name, removes the image)
add_filter('get_the_archive_title',function($title){ if( is_author() ){ $title = '<span class="vcard">'.get_the_author().'</span>'; return $title; } },15,1);
As for the description:
It’s added through this:
add_action( 'generate_after_archive_title', 'generate_do_archive_description' );
While we can just do
remove_action( 'generate_after_archive_title', 'generate_do_archive_description' );
, the problem is, this will affect the category descriptions as well.That said, we can try this:
function alter_author_desc(){ $term_description = term_description(); if ( ! empty( $term_description ) ) { printf( '<div class="taxonomy-description">%s</div>', $term_description ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } if ( get_the_author_meta( 'description' ) && is_author() ) { return; } /** * generate_after_archive_description hook. * * @since 0.1 */ do_action( 'generate_after_archive_description' ); } add_action( 'after_setup_theme','generate_remove_author_details' ); function generate_remove_author_details() { remove_action( 'generate_after_archive_title', 'generate_do_archive_description' ); add_action( 'generate_after_archive_title', 'alter_author_desc' ); }
This is so nothing is returned when you’re in author archive pages.
Within the code, if you want to do something different on the author archive pages, do it inside the
if ( get_the_author_meta( 'description' ) && is_author() ) {...}
condition. Replace thereturn;
with any code you want to do.February 5, 2021 at 8:31 am #1647204TomExcellent, this solved my problem. Appreciate the great explanation!
February 7, 2021 at 10:29 pm #1649756ElvinStaffCustomer SupportNo problem. Glad you got it sorted. 😀
-
AuthorPosts
- You must be logged in to reply to this topic.