Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1491447

    Hi everyone,
    I would like to know how to edit the author page. This page shows all the articles written by the author. Question #1: Is it possible to display these items in a grid or list layout? The articles are now shown in full. On the blog layout I set the grid, but it is not shown here.
    Question number 2: alternatively, can I customize the author page as I prefer? Maybe only showing some articles and not all?

    Thanks for your support!

    #1491540

    sadly the filter avf_post_slider_args is not implemented in the author archive.
    It is ruled by author.php and loop-author.php.

    So we have to built a custom loop-author.php.

    Edit: see solution …

    the column count inside that snippet is added as custom-class – so we can react on it by css setting.

    #1491541

    just a moment – pastebin code is edited now _ the read-more button is buggy. …
    …. it is fixed now – download from above

    … maybe we should take out the readmore button – and place it as a sibling to av-author-grid-content. So we can then position it to always be on the bottom of equal height articles. … more to come

    i try now to have a pagination by atts settings.

    #1491596

    I may not have solved it elegantly, but the pagination now works as it should.

    Edit : see solution on: https://kriesi.at/support/topic/how-to-customize-the-author-page/#post-1491667

    #1491601
    #1491604

    PS – You can see that this method works well – but if you feel anxious about trying it out, please ask a mod to implement it for you.

    Edit : see solution on: https://kriesi.at/support/topic/how-to-customize-the-author-page/#post-1491667

    #1491653

    So far, it only displays posts – now I’m trying to implement a way to select the post type via $atts['post_types'] – so the author page could show all posts and portfolios from an author.
    btw. Something that handles the standard file ‘loop-author.php’ in exactly the same way: it only displays the posts.
    Will I manage to fix that too?

    #1491667

    now my final solution is – to upload 3 files to the child-theme includes folder:

    /wp-content/themes/enfold-child/
    └── includes/
      └── loop-author.php ← PHP Loop (loads the css once)
      └── loop-about-author.php
      └── loop-author.css ← all Styles (Grid + List)

    loop-author.php: https://pastebin.com/yaXj5Zfw
    loop-about.php: https://pastebin.com/QQ84LGaw
    loop-author.css: https://pastebin.com/zTJMtth9

    to style the author page now are two entries for child-theme functions.php

    // 1. Configure layout and settings
    add_filter( 'avf_author_loop_args', function( $atts, $context ) {
        if( $context == 'author' ) {
            $atts['type']              = 'list';               // 'grid' or 'list' Layout
            $atts['columns']           = 4;                    // columns count
            $atts['image_size']        = 'gallery';            //  image-size
            $atts['contents']          = 'excerpt_read_more';  // Content-Type
            $atts['items']             = -1;                   // Posts per page
            $atts['paginate']          = 'no';                // Pagination  on/off  (yes or no)
            $atts['show_modified_date'] = 'yes';               // 'yes' = shows  "Updated: XX"
            $atts['orderby']           = 'date';               // orderby : 'date', 'modified', 'title', 'rand', 'comment_count'
            $atts['order']             = 'DESC';               // order: 'DESC' (newest or Z-A) or 'ASC' (oldest or A-Z)
    	$atts['fallback_image']     = get_stylesheet_directory_uri() . '/includes/fallback.jpg';  // an url or  'placeholder'
    	$atts['post_types'] 		= array('post', 'portfolio');    	// 	count posts or portfolios or both
        }
        return $atts;
    }, 10, 2);
    
    // 2.  IMPORTANT: Customise query for pagination, sorting and post types
    add_action( 'pre_get_posts', function( $query ) {
        if( ! is_admin() && $query->is_main_query() && is_author() ) {
            // Get the filtered arguments from above
            $default_args = array(
                'items'      => get_option('posts_per_page', 12),
                'orderby'    => 'date',
                'order'      => 'DESC',
                'post_types' => array('post')
            );
            $atts = apply_filters( 'avf_author_loop_args', $default_args, 'author' );
            
            // Set Query-Parameters
            $query->set( 'posts_per_page', $atts['items'] );
            $query->set( 'orderby', $atts['orderby'] );
            $query->set( 'order', $atts['order'] );
            
            // Set post types - IMPORTANT: even if there is only one type
            if( ! empty( $atts['post_types'] ) && is_array( $atts['post_types'] ) ) {
                // WordPress requires 'any' or an array with multiple types
                if( count( $atts['post_types'] ) == 1 ) {
                    $query->set( 'post_type', $atts['post_types'][0] );
                } else {
                    $query->set( 'post_type', $atts['post_types'] );
                }
            }
        }
    }, 999 );

    see result page : https://basis.webers-testseite.de/author/guenni007/
    Unfortunately, no translation for But we are proud to say that %s contributed %s entries already. has been added to the (at least German) lang files yet. That is why it is in English on my example page.

    i tested all 3 blog styles – it works on all of them.

    #1491671

    just for understanding – these are the default values from loop-author.php:

    // Default arguments for Author Loop
    $default_args = array(
        'type'              => 'grid',
        'columns'           => 4,
        'items'             => get_option('posts_per_page', 12), // WordPress setting, fallback: 12
        'contents'          => 'excerpt_read_more',
        'preview_mode'      => 'auto',
        'image_size'        => 'portfolio',
        'paginate'          => 'no',
        'class'             => '',
        'show_modified_date' => 'no',  // 'yes' or 'no' - shows "Updated: XX" if post was modified
        'orderby'           => 'date',  // 'date', 'modified', 'title', 'rand', 'comment_count', 'menu_order'
        'order'             => 'DESC',  // 'DESC' (newest first) or 'ASC' (oldest first)
        'fallback_image'    => 'placeholder',      //  'placeholder'  or URL to fallback image 
        'post_types'        => array('post'), // Array: array('post'), array('portfolio'), or array('post', 'portfolio')
    );
    
    // Content Options for 'contents' parameter:
        // 'title'                  - Title only
        // 'title_read_more'        - Title and Read More button
        // 'only_excerpt'           - Excerpt only (no title)
        // 'only_excerpt_read_more' - Excerpt and Read More button (no title)
        // 'excerpt'                - Title and Excerpt
        // 'excerpt_read_more'      - Title, Excerpt and Read More button (default)
    
    

    if you like to have it this way (grid, 4columns, exerpt with readmore, only posts ordered by date – newest first) you do not need to set the filter.
    Then only the second part is needed inside functions.php.

    The filter could do more – you can even differ between authors – f.e by author name. :

    // 1. Layout for different authors by ID
    add_filter( 'avf_author_loop_args', function( $atts, $context ) {
        if( $context == 'author' ) {
            // Common settings for all author pages
            $atts['items']             = -1;
            $atts['image_size']        = 'gallery';
            $atts['contents']          = 'excerpt_read_more';
            $atts['post_types']         = array('post', 'portfolio'); 
    		
    	// Fallback-Image from Media Library (Attachment-ID)
            $fallback_id = 2052;  // Your image ID from Media Library
            $fallback_img = wp_get_attachment_image_src($fallback_id, $atts['image_size']);
            $atts['fallback_image'] = $fallback_img ? $fallback_img[0] : 'placeholder';
            
            $author_slug = get_query_var( 'author_name' );
    
            // Individual configuration for a specific author
            if( $author_slug == 'guenni007' ) {
                $atts['type']              = 'grid';
                $atts['columns']           = 3;
            } 
            else {
                // default setting for the rest
                $atts['type']              = 'list';
            }
        }
        return $atts;
    }, 10, 2);

    the fallback image i get from media-library with the attachment ID
    Advantage of this solution – the fallback image is based on the selected image size setting.

    see:
    grid for guenni007: https://basis.webers-testseite.de/author/guenni007/
    list for johndoe: https://basis.webers-testseite.de/author/johndoe/

    #1491686

    i implemented the possibility to add a custom class set on the grid container (div.av-author-loop-container)
    and implemented a css for that custom-class on loop-author.css to rule the column-count for all screen width :

    /* ======================================================================
    	OPTIONAL: AUTO-FIT GRID  in filter for automatic responsive columns
    	Use    $atts['class']   = 'auto-fit-grid';   
       ====================================================================== */
    #top.author .av-author-grid-container.auto-fit-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)) !important;
    }

    this means: Each column must have a minimum width of 250px — the entire width is then filled with columns based on this basis.

    _______________

    in list view – if you do not like to show the featured image in cover mode – then add to your quick css:

    #top.author .av-author-list-image img {
      height: 100%; /* === unset - will bring the image to top === */
      object-fit: contain;  /* === contain - will show the whole image without crop === */
    }
    #1491693

    Hi,

    Thanks for sharing @guenni007 :-)

    Best regards,
    Rikard

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