- This topic has 63 replies, 3 voices, and was last updated 1 year, 7 months ago by Tom.
June 28, 2019 at 12:56 pm #944170TomLead DeveloperLead Developer
The redirect is only working for one author?
is_author()should be true for all authors.
Is there a link to another author page I can check out?June 28, 2019 at 6:16 pm #944319culpable
Ah my bad. To clarify I meant standardize it so that it works for *different* authors.
So that if I have an author named Bob, all instances of Bob’s name mentioned below the h1s will go to
If I have an author named Jane, all instances of Jane’s name mentioned below the h1s will go to
/author/Jane/June 29, 2019 at 8:04 am #944664TomLead DeveloperLead Developer
Something like that is more complex, I suggest setting up 301 redirects for each author. That way will likely be the easiest/most SEO friendly method.June 29, 2019 at 8:41 pm #944998culpable
Fair enough Tom, that’s a good solution – although a bit more manual than I’d like.
I realise I’m taking up a lot of you two gentlemen’s time…. but I have some good news.
I really liked the solution David posted here https://generatepress.com/forums/topic/custom-author-archive-pages/page/3/#post-939284 as it seemed to correctly 404 the
/page/*x*/as well as only showing 5 wordpess pages. But I couldn’t figure out why it wasn’t working for me (I was getting a “Nothing found”).
I tried doing as David suggested – I added the
author.phpand completely deleted my
functions.php. No dice. Made sure everything was up to date (wordpress, GP, etc.), removed all code from the
Elementsarea…. still no dice.
I thought about the differences between David’s test site and mine. Then it hit me… David had some wordpress posts published, and I didn’t.
As soon as I published a single wordpress posts… bingo. The author page now correctly displays the last 5 WordPress pages written by the author.
author.phpcode (here), I’d bet money that it was this part:
if ( have_posts() ) : do_action( 'generate_archive_title' ); query_posts(array( 'post_type' => 'page', 'posts_per_page' =>5 ) );
if…. have posts. I didn’t have any posts. So the code wasn’t working. Once I published a single post – even if I no indexed it, it’s now working. Excellent!
Just a few more questions for you if you don’t mind:
1. Is there an easy adjustment to this code so that I don’t actually need to have any wordpress posts published for it to work?
2. Is there a way to exclude a page by ID in this
3. I notice that the little “snippet” that’s taken from the article before the “Read more” button is different in the author archives vs. what WordPress show posts uses (i.e. Tom’s plugin). WordPress show posts (WPSP) seems to (correctly) ignore the table of contents, while the author archives include them (making the article snippet look like gibberish). Is there an easy fix to make the snippets for the archive the same as WPSP?
Thank you so much guys. Love your work.June 30, 2019 at 9:40 am #945398TomLead DeveloperLead Developer
1. This part of the code executes when there aren’t any posts:
get_template_part( 'no-results', 'archive' );
You can replace that with anything you want and it should show up if there are no posts.
2. I think you’re looking for:
So your query would be:
query_posts( array( 'post_type' => 'page', 'posts_per_page' => 5, 'post__not_in' => array( 10 ) // post ID to exclude ) );
3. Which snippet are we talking about?June 30, 2019 at 4:22 pm #945582culpable
1. Ah, excellent. So there is no “
have_pages()” equivalent that I can replace the
have_posts()with? (i.e. check if the author has any WordPress pages, not WordPress posts)
2. Works like a charm, thank you sir.
3. The snippet that the author archives and WPSP takes from the article itself, just before the “Read More” button. Here’s an example here: https://imgur.com/a/CkrvTur You can see that WPSP has ignored the Table of contents, while the author archives haven’t. Your code seems “smarter”.
Thank you very much for your time Tom 🙂June 30, 2019 at 8:14 pm #945646TomLead DeveloperLead Developer
have_posts()will work with whatever is queried, whether it’s posts or pages.
3. Ah, that’s because it’s displaying an excerpt which will strip HTML. If you want to display the full content, you need to tell it to display the full content instead of the excerpt.
Let me know if you need more info 🙂July 1, 2019 at 6:47 am #945976culpable
1. Hmmm well in that case, what explains the behavior I described here: https://generatepress.com/forums/topic/custom-author-archive-pages/page/4/#post-944998 i.e. the author archives showing “nothing found” until I published a wordpress “posts” (even though I already had wordpress pages published). Apologies for my ignorance.
2/3. I’d like it to display the way our WPSP do (without the ToC). I’d love some help with that 🙂July 1, 2019 at 9:29 am #946257TomLead DeveloperLead Developer
1. Can you link me to this nothing found page?
2. Have you tried setting the Content type option to “Excerpt” in Customize > Layout > Blog? That should make it exactly like WPSP.July 1, 2019 at 4:17 pm #946541culpable
1. Sure thing. Link is on this page. To reproduce this page, the only thing I did was change the only published post on the blog written by the author from published -> draft.
2. It’s currently set to “Excerpt”July 1, 2019 at 6:39 pm #946592TomLead DeveloperLead Developer
1. But there are published pages attributed to the same author? It’s hard to tell without seeing the actual page.
2. And the posts are displaying HTML? Can I see this as well anywhere?July 2, 2019 at 5:52 am #946863culpable
1. Yes there are published pages assigned to the author. As soon as I publish a “post” with that author, the 5 pages show up on the author archive page. As soon as I switch the post to draft, the pages disappear. The link to the author page is shown here, in the description. If you can’t see it, let me know and I’ll email it to you.
2. Yeah sure, here is an example screenshot of a post here. I can’t show you it as an author archive atm, as I’m currently showing you how it looks with “Nothing found” (as per question 1).
Thank you very much for your help Tom 🙂July 2, 2019 at 9:41 am #947182TomLead DeveloperLead DeveloperJuly 3, 2019 at 3:42 am #947746culpable
It works… kind of.
The pages are now appearing, but I’ve lost the author name + author display picture that is typical of author archive pages, as seen here: https://imgur.com/a/cYeHYiF
Note that this page stays the same whether I publish a WordPress “post” or leave it as a draft (remembering there are no WordPress posts currently on the site).July 3, 2019 at 9:47 am #948156TomLead DeveloperLead Developer
Hmm, that’s likely happening because
query_posts()is taking over the entire query. The only thing I can think of to get around it is using the
pre_get_postsaction I was mentioning earlier in this topic.
I’m not even sure how your current method is preventing pagination – nothing in the function is telling WordPress not to paginate.
- You must be logged in to reply to this topic.