[Resolved] Edit Author Page To Show Pages

Home Forums Support [Resolved] Edit Author Page To Show Pages

Home Forums Support Edit Author Page To Show Pages

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #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.

    #746109
    Tom
    Lead Developer
    Lead Developer

    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 πŸ™‚

    #746298
    culpable

    Thanks for your help Tom.

    So do I just add this code to the functions.php file of my child theme? πŸ™‚

    #746332
    Leo
    Staff
    Customer Support

    Yes πŸ™‚

    #746647
    culpable

    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,

    #746900
    Tom
    Lead Developer
    Lead Developer

    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.

    #747615
    culpable

    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

    #748272
    Tom
    Lead Developer
    Lead Developer

    Hmm, try adding this function:

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

    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

    #748907
    Tom
    Lead Developer
    Lead Developer

    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.

    #749166
    culpable

    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?

    #749213
    Tom
    Lead Developer
    Lead Developer

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

    #749261
    culpable

    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?

    #749273
    Tom
    Lead Developer
    Lead Developer

    Instead, I would do this:

    body.page {
      background-color:white
    }
    #749285
    culpable

    Arrr yes – even better!

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

Viewing 15 posts - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.