This code is an extension of another post about how to create an author contributors page template.
The code adds extra user profile fields for social media links.
On top of this it uses the native Dashicons already included in WordPress.
Code Installation
There’s 3 blocks of code which need to be installed.
- Create a new file named contributors_page.php using a text editor like Notepad++ and copy the code under contributors_page.php into your new file. Save the file to desktop and upload to the root directory of your child theme.
- Copy the PHP code under functions.php and paste it at the end of your child themes functions.php file.
- Copy the CSS code under style.css and paste it at the end of your child themes style.css file before the start of your Media Queries section.
Update: This page template now only displays the social media icon if the field is populated. If not, it won’t display.
Note: The code lists all authors who are assigned the contributor role only & has been tested on the Genesis default theme. May need tweaking for use on other themes.
OK – got this working as a shortcode, woot! One thing is bedeviling me – I want to randomize it rather than have it ordered by the number of posts. It doesn’t seem like get_users has an option to randomize the order (for either
order
ororderby
). How can I do that?Also, even though I’m using it in a widget as a shortcode, the output is display above the widget title. I have no idea how that is happening.
You could replace get_users with WP_User_Query but that doesn’t seem to include the standard WP_Query Order & Orderby Parameters either, not sure why so i’ll see if i can find out for you.
Maybe you are returning it before returning the widget?
I found a really simple way to randomize – before the
foreach
statement, I added this:shuffle( $contributor_ids );
I found it by taking a look at the Author Avatars plugin to see how they did it. Maybe it’s an option you can add to your code 🙂
On the shortcode being called before the widget, I’m not sure how that works – I’m still quite the noob.
Cool.
Haven’t seen that function before.
Thanks for the great feedback.
Try pre_get_posts as another function for RAND
And …. because I’m using a shortcode where the function is not returning a string, I had to use output buffering to get the widget title to appear above the shortcode output. Plus I figured out how to limit the results to 1 random contributor. Now to figure out the last steps of creating a custom profile field to upload images and to display those images…
This is great, thanks!
However, the social icons appear whether or not the relevant fields have any date input into them, which is a bit a problem (not everyone has relevant social links).
I’ve not added any links for into the relevant profile fields for the vast majority or those contributors, and yet the social icons are displaying for everyone
Any idea how I can change/ fix this?
Thanks!
You will need to modify the code to get it to do exactly what you want.
Will this also be translated for Genesis? I noticed the page template code doesn’t look like the template code for a Genesis theme.
Hello Erica
You can add translation if you like. http://codex.wordpress.org/Translating_WordPress
There’s different ways to code templates.
The reason i coded it this way is so it works with any theme.
Just wrote the code specifically for Genesis. Thanks for the idea Erica http://wpsites.net/web-design/genesis-users-page-template/
Thanks a lot for this useful tutorial and scripts.
Accept only a little suggestion also for your follower… I found the email to add http:// before then in functions.php modify the following line:
What is the difference?
This is amazing. I however how two issues… all the links are defaulting to the site’s links or my links on my profile not theirs and in the array section, how do I edit out or edit in only certain contributors?
Code modifications are not provided for free.
I would need to inspect and test your code to see where you went wrong with the installation.