Community Forums › Forums › Archived Forums › General Discussion › Author's Posts Loop in author.php page
Tagged: author.php, authors, loop
- This topic has 3 replies, 2 voices, and was last updated 7 years, 7 months ago by
lomaymi.
-
AuthorPosts
-
April 27, 2016 at 11:16 am #184534
lomaymi
MemberI'm making a custom author.php page with the following format:
1. Custom profile pic (no gravatar)
2. Author Name
3. Author social networks
4. Author biographical information
5. Archive headline and description text
6. Author blog post loopI managed to make everything from 1 to 5 exactly the way I wanted, but I can't figure out how to call author posts loop. I want to be able to have full control of the position of blog post titles, featured images, excerpt, etc. Here what I have so far on my author.php:
<?php get_header(); //* Variable to call current author of page $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); ?> <!-- Author Profile Picture from custom profile picture url--> <div class="authorpage_pic"> <?php if ( get_the_author_meta( 'avatar' ) != '' ): ?><img src="<?php echo get_the_author_meta( 'avatar' ); ?>"><?php endif; ?> </div> <!-- Author first and last names--> <h2 align="center" ><?php echo $curauth->first_name; ?> <?php echo $curauth->last_name; ?></h2> <!-- Author social media accounts--> <div class="authorpage_social"> <ul class="social-icons"> <?php if ( get_the_author_meta( 'facebook' ) != '' ): ?> <li><a href="<?php echo get_the_author_meta( 'facebook' ); ?>" target="_blank"><i class="fa fa-facebook"></i></a></li> <?php endif; ?> <?php if ( get_the_author_meta( 'twitter' ) != '' ): ?> <li><a href="https://twitter.com/<?php echo get_the_author_meta( 'twitter' ); ?>" target="_blank"><i class="fa fa-twitter"></i></a></li> <?php endif; ?> <?php if ( get_the_author_meta( 'linkedin' ) != '' ): ?> <li><a href="<?php echo get_the_author_meta( 'linkedin' ); ?>" target="_blank"><i class="fa fa-linkedin"></i></a></li> <?php endif; ?> <?php if ( get_the_author_meta( 'googleplus' ) != '' ): ?> <li><a href="<?php echo get_the_author_meta( 'googleplus' ); ?>" target="_blank"><i class="fa fa-google-plus"></i></a></li> <?php endif; ?> <?php if ( get_the_author_meta( 'instagram' ) != '' ): ?> <li><a href="<?php echo get_the_author_meta( 'instagram' ); ?>" target="_blank"><i class="fa fa-instagram"></i></a></li> <?php endif; ?> <?php if ( get_the_author_meta( 'youtube' ) != '' ): ?> <li><a href="<?php echo get_the_author_meta( 'youtube' ); ?>" target="_blank"><i class="fa fa-youtube-play"></i></a></li> <?php endif; ?> <?php if ( get_the_author_meta( 'user_email' ) != '' ): ?> <li><a href="mailto:<?php echo get_the_author_meta( 'user_email' ); ?>" target="_blank"><i class="fa fa-envelope"></i></a></li> <?php endif; ?> <?php if ( get_the_author_meta( 'user_url' ) != '' ): ?> <li><a href="<?php echo get_the_author_meta( 'user_url' ); ?>" target="_blank"><i class="fa fa-desktop"></i> </a></li> <?php endif; ?> </ul> </div> <!-- Author biographical info--> <p><?php echo $curauth->description; ?></p> <!-- Author archive headline and description text--> <?php if ( ! is_author() ) return; $headline = get_the_author_meta( 'headline', (int) get_query_var( 'author' ) ); $intro_text = get_the_author_meta( 'intro_text', (int) get_query_var( 'author' ) ); $headline = $headline ? sprintf( '<h1 %s>%s</h1>', genesis_attr( 'archive-title' ), strip_tags( $headline ) ) : ''; $intro_text = $intro_text ? apply_filters( 'genesis_author_intro_text_output', $intro_text ) : ''; if ( $headline || $intro_text ) printf( '<div %s>%s</div>', genesis_attr( 'author-archive-description' ), $headline . $intro_text ); // Author blog post loop get_footer(); ?>
Any suggestions to achieve what I want will be greatly appreciated.
April 27, 2016 at 11:39 am #184536Victor Font
ModeratorTake a look at the source code for the WordPress wp_list_authors function and see how they do it. Perhaps it will provide some ideas: https://developer.wordpress.org/reference/functions/wp_list_authors/
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?April 28, 2016 at 12:36 am #184583lomaymi
MemberJust figure it out after many hours of trial and error. Will post my code here so anyone can use as reference:
<!-- AUTHOR BLOG POST LOOP 2 COLUMNS --> <h2>Post by <?php echo $curauth->first_name; ?></h2> <br> <!-- Set parameters to display in posts loops--> <?php $args1 = array( 'numberposts' => 2, 'offset' => 0, 'author' => $authordata->ID, 'post_not_in' => array( $post->ID ) ); $args2 = array( 'numberposts' => 2, 'offset' => 2, 'author' => $authordata->ID, 'post_not_in' => array( $post->ID ) ); // This is for author remaining blog posts $args3 = array( 'offset' => 4, 'author' => $authordata->ID, 'post_not_in' => array( $post->ID ) ); ?> <div class="author_columns"> <!-- First column loop posts --> <div class="one-half first"> <?php query_posts('showposts=2'); ?> <?php $posts = get_posts($args1); foreach ($posts as $post) : start_wp(); ?> <?php static $count1 = 0; if ($count1 == "2") { break; } else { ?> <a href="<?php the_permalink() ?>"><?php the_post_thumbnail('medium'); ?> </a> <h3><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3> <?php the_excerpt (); ?> <?php $count1++; } ?> <?php endforeach; ?> </div> <!--Second column loop posts offset 2--> <div class="one-half"> <?php query_posts('showposts=2'); ?> <?php $posts = get_posts($args2); foreach ($posts as $post) : start_wp(); ?> <?php static $count2 = 0; if ($count2 == "2") { break; } else { ?> <a href="<?php the_permalink() ?>"><?php the_post_thumbnail('medium'); ?> </a> <h3><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3> <?php the_excerpt (); ?> <?php $count2++; } ?> <?php endforeach; ?> </div> </div> <!--AUTHOR REMAINING BLOG POST LIST AFTER FOURTH ENTRY --> <ul class="author_post_list"> <?php $myposts = get_posts( $args3 ); foreach ( $myposts as $post ) : setup_postdata( $post ); ?> <li><h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4></li> <?php endforeach; wp_reset_postdata();?> </ul>
Here are a couple of resources I found very useful (couldn’t post hyperlinks, it appears this marks message as spam. Just do a Google search):
- Code Reference: the_excerpt()
- <Codex: Post Thumbnails
- Codex: Template Tags/get posts
- How to Display Related Posts by Same Author in WordPress
- get_posts - get all posts by author id
- 6 Ways to Display WordPress Post Content in Multiple Columns
If you got any questions about my code feel free to reply.
May 8, 2016 at 10:19 am #184582lomaymi
MemberJust figure it out after many hours of trial and error. Will post my code here so anyone can use as reference:
<!-- AUTHOR BLOG POST LOOP 2 COLUMNS --> <h2>Post by <?php echo $curauth->first_name; ?></h2> <br> <!-- Set parameters to display in posts loops--> <?php $args1 = array( 'numberposts' => 2, 'offset' => 0, 'author' => $authordata->ID, 'post_not_in' => array( $post->ID ) ); $args2 = array( 'numberposts' => 2, 'offset' => 2, 'author' => $authordata->ID, 'post_not_in' => array( $post->ID ) ); // This is for author remaining blog posts $args3 = array( 'offset' => 4, 'author' => $authordata->ID, 'post_not_in' => array( $post->ID ) ); ?> <div class="author_columns"> <!-- First column loop posts --> <div class="one-half first"> <?php query_posts('showposts=2'); ?> <?php $posts = get_posts($args1); foreach ($posts as $post) : start_wp(); ?> <?php static $count1 = 0; if ($count1 == "2") { break; } else { ?> <a>"><?php the_post_thumbnail('medium'); ?> </a> <h3><a>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3> <?php the_excerpt (); ?> <?php $count1++; } ?> <?php endforeach; ?> </div> <!--Second column loop posts offset 2--> <div class="one-half"> <?php query_posts('showposts=2'); ?> <?php $posts = get_posts($args2); foreach ($posts as $post) : start_wp(); ?> <?php static $count2 = 0; if ($count2 == "2") { break; } else { ?> <a>"><?php the_post_thumbnail('medium'); ?> </a> <h3><a>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3> <?php the_excerpt (); ?> <?php $count2++; } ?> <?php endforeach; ?> </div> </div> <!--AUTHOR REMAINING BLOG POST LIST AFTER FOURTH ENTRY --> <ul class="author_post_list"> <?php $myposts = get_posts( $args3 ); foreach ( $myposts as $post ) : setup_postdata( $post ); ?> <li><h4><a>"><?php the_title(); ?></a></h4></li> <?php endforeach; wp_reset_postdata();?> </ul>
Here are a couple of resources I found very useful:
- Code Reference: the_excerpt()
- Codex: Post Thumbnails
- Codex: Template Tags/get posts
- How to Display Related Posts by Same Author in WordPress
- get_posts - get all posts by author id
- 6 Ways to Display WordPress Post Content in Multiple Columns
If you got any questions about my code feel free to reply.
-
AuthorPosts
- The topic ‘Author's Posts Loop in author.php page’ is closed to new replies.