Site logo

Archived topic

Edit Author Page To Show Pages

15 replies · Started by culpable on December 1, 2018

Viewing posts 1–15 of 16

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.

Hi 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 :)

Thanks for your help Tom.

So do I just add this code to the functions.php file of my child theme? :)

Yes :)

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,

1. 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.

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

Hmm, try adding this function:

add_filter( 'generate_blog_columns', function( $columns ) {
    if ( 'page' === get_post_type() && ! is_singular( 'page' ) ) {
        return true;
    }

    return $columns;
} );

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

That'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.

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?

Removing that custom CSS I mentioned above will fix that issue.

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?

Instead, I would do this:

body.page {
  background-color:white
}

Arrr yes – even better!

Thank you for all of your help Tom. Love your work xoxo

This archived topic is closed to new replies.