- This topic has 15 replies, 3 voices, and was last updated 4 years, 5 months ago by
Tom.
-
AuthorPosts
-
December 1, 2018 at 8:57 pm #745752
culpable
Hiya,
I’m trying to edit the default wordpress author pages to show pages made by the author β not just posts.
The way I think I might achieve this is by creating a custom page called “Author Page”, and then using the “WP Show Posts” plugin (I’ve got premium) to show all pages/posts made by the author? Would I do this in the More Settings -> Author ID section?
But still I’m having trouble seeing how I can:
– Make this scale for other authors (as this would only be specific to one author?)
– How do I show the little name + picture that comes up by default at the top of author pages? Is this an existing hook?Thank you in advanced for your help.
December 2, 2018 at 8:45 am #746109Tom
Lead DeveloperLead DeveloperHi there,
It would be easier to tell WordPress to include pages in the standard theme archives.
For example:
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' ) ); } } );
That should do it π
December 2, 2018 at 3:08 pm #746298culpable
Thanks for your help Tom.
So do I just add this code to the functions.php file of my child theme? π
December 2, 2018 at 4:31 pm #746332Leo
StaffCustomer SupportYes π
December 3, 2018 at 6:05 am #746647culpable
Thanks for your help guys. I tried implementing the above code and it’s not quite working as expected. Here’s some annotated images: https://imgur.com/a/xQLBA94
Issues:
– Sidebar has disappeared from the top of the page β it’s not appearing at the bottom of the page
– The padding is not working
– Is there any way to exclude the static home page?Thanks guys,
December 3, 2018 at 8:47 am #746900Tom
Lead DeveloperLead Developer1. There seems to be a closing
</div>
element where there shouldn’t be. Anything added via Hooks? Any HTML in widgets? If not, can you deactivate Autoptimize so I can view your source more clearly?2. You’ll want to update this CSS:
.page .inside-article { max-width: 700px; margin: auto; padding: 20px; }
To this:
body.page .inside-article { max-width: 700px; margin: auto; padding: 20px; }
3. You could try changing your function to this:
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( 10 ) ); } } );
You’d just need to update
10
with the ID of the home page.December 4, 2018 at 4:48 am #747615culpable
Thank you very much for your help Tom.
As per your recommendations:
1. I don’t think so. I have 2 small hooks in the page β shown here: https://imgur.com/a/WVtScwV. The only other bit of custom code I can think of is the footer. But this has a single anchor tag and no divs.2. Updated as per your code. The issue is still there, so I have disabled the HTML + CSS optimisation
3. Updated β and the home page is gone! Thanks Tom π
Please let me know if you need any more information Tom. Thanks again
December 4, 2018 at 6:29 pm #748272Tom
Lead DeveloperLead DeveloperHmm, try adding this function:
add_filter( 'generate_blog_columns', function( $columns ) { if ( 'page' === get_post_type() && ! is_singular( 'page' ) ) { return true; } return $columns; } );
December 4, 2018 at 7:00 pm #748284culpable
Hey Tom,
Thanks for the code snippit mate. So that’s filtering the generate_blog_columns function?
I’ve added it to the page and it looks like we’re almost there. It’s just that now the alignment of pages is “wonky” (they’re sticking out on the left hand side). Took some screenshots: https://imgur.com/a/siA1BYy
Also, I notice that the author pages nicely seperate the posts/pages/sidebar in white while the background is grey. Is there a way to do this for my static home page? (which I generated using WP Show Posts?). Screenshots to illustrate what I’m trying to say: https://imgur.com/a/tIxrbJV
December 5, 2018 at 9:40 am #748907Tom
Lead DeveloperLead DeveloperThat’s happening because of this custom CSS:
.page { background-color: white; }
Unfortunately, WP Show Posts doesn’t have control over the container it’s within. So you’d have to manually remove the background color from that page, and add the background color to each WPSP container.
December 5, 2018 at 3:07 pm #749166culpable
Ah okay, makes sense. Thanks Tom.
What can I do about these misaligned pages and lack of padding: https://imgur.com/a/siA1BYy
Is there any way to fix this?
December 5, 2018 at 4:03 pm #749213Tom
Lead DeveloperLead DeveloperRemoving that custom CSS I mentioned above will fix that issue.
December 5, 2018 at 6:04 pm #749261culpable
Oh sorry Tom! I thought that was regarding a different query.
When I remove this custom CSS you’re right – it does fix it.
But if I want to have .pages with a white background (because I’m using pages similar to posts), while having the author page excluded, I came up with this CSS:
.page{ background-color:white } .author .page{ background-color:#f1f1f1 }
Where #f1f1f1 is the old background color. This seems to work, but is there a better way to do this?
December 5, 2018 at 6:18 pm #749273Tom
Lead DeveloperLead DeveloperInstead, I would do this:
body.page { background-color:white }
December 5, 2018 at 6:40 pm #749285culpable
Arrr yes β even better!
Thank you for all of your help Tom. Love your work xoxo
-
AuthorPosts
- You must be logged in to reply to this topic.