Hot answers tagged author-template
5
You can modify all main queries before they happen via the pre_get_posts action and a check if is_main_query:
function wpa75492_post_type_query( $query ) {
if ( $query->is_main_query() ) {
$query->set( 'post_type', array( 'book' ) );
}
}
add_action( 'pre_get_posts', 'wpa75492_post_type_query' );
5
You will want to implement that using AJAX. Read these two articles from the Codex for further information about integrating Wordpress with some AJAX action:
AJAX
AJAX in Plugins
Just to give you a head start, you will want something like this:
Client-side (Javascript)
$(element).click(function() {
var data = {
action: ...
3
Basic debugging...
$current_author = get_query_var('author');
var_dump($current_author);
... would reveal that $current_author is a string, not an object. The problem is that you are trying to use the string as an object in the query.
get_posts( 'author='.$current_author->id.'&posts_per_page=1&order=DESC&orderby=post_date' );
Change ...
2
<?php if(!empty($curauth->description)) { ?>
<div class="title">About me</div>
<div class="descwrap">
<div class="descinner">
<?php echo $curauth->description; ?>
</div>
</div>
<?php } ?>
This should work for you. It checks if the variable is empty or not ...
2
Could be because you are passing an array of array try this:
<?php
$my_query = new WP_Query();
$my_query->query(array( 'post__in' => $curauth->user_favourite_post));
while ($my_query->have_posts()) : $my_query->the_post();
?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
...
2
You can do this using both client-side and server-side validation. If you're doing something on the client-side then you should duplicate the functionality on the server, too. Modern debugging tools make it far too easy to circumvent JavaScript functionality.
This questions lends itself well to begin solved as plugin, so I'm approaching it as such.
First, ...
2
You're going to want to use the author_template filter to process this. Just to clarify, the filter's "author" means all users, it appears. I'm not sure why. This will be called while the backend is deciding which template page to use when showing a user's profile on your site. You need to add an author-editor.php file and then filter to it if the user ...
2
http://codex.wordpress.org/Function_Reference/get_comments#Parameters
your problem is using author_email, you need user_id
i just use similar script.
<?php
$args = array(
'user_id' => $user->ID,
'number' => 10, // how many comments to retrieve
'status' => 'approve'
);
$comments = get_comments( $args ...
1
You've already used sanitize_title once in you code. You need to use that in again, inside the wpse5742_author_link function.
$link = str_replace( $author_nicename, sanitize_title($author_nickname), $link );
That should take care of the spaces. Another other option is to use urlencode but sanitize_title keeps things consistent.
I (minimally) tested your ...
1
As an alternative to "current_user_can" WordPress provides "user_can" which will take a User object or ID as a parameter. Combining your top code and the bottom code with the new function it would look like this:
$author_user = $wp_query->get_queried_object(); // the queried object in 'author.php' should be an author user
if (user_can($author_user, ...
1
I found the answer to this from @bybloggers answer found here. http://wordpress.stackexchange.com/a/58793/12920
I modified his code very slightly to tailor it to my needs, but this is the code that worked for me and was exactly what I was looking for:
// Create the query var so that WP catches the custom /member/username url
function ...
1
What you need here is to shuffle all the array elements & then display them. But since php's shuffle() function doesn't preserve array key associations, here's a version that does.
function shuffle_assoc(&$array) {
$keys = array_keys($array);
shuffle($keys);
foreach($keys as $key) {
$new[(string)$key] = $array[$key];
}
...
1
How are you creating the author's link?
If you put in your template:
<?php the_author_posts_link(); ?>
It will write the author's name and link for the current post.
To modify the template for the author page, wordpress search for the following files in your theme's folder (in this order):
author-{nicename}.php
author-{id}.php
author.php
...
1
Use wp_generate_password() to generate passwords. For example, you could add a button to the user profile to get a new password per AJAX.
And you have a security vulnerability in your current code: $getId, the substring from a visitor request may contain malicious code. Always escape request data. Read Data Validation for more information, especially ...
1
To access the author user object outside of the loop on an author archive, you can do the following:
global $curauth;
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
echo 'This is the author page of '.$curauth->display_name;
1
If you're trying to get user data for the displayed profile, you can do it like so:
$thisauthor = get_userdata(intval($author));
That'll return an object filled with everything you need. For instance, if you need the user ID, you can call it like so:
$thisauthor->ID
I use this extensively on the profiles on my site: http://androidandme.com/user/clark
...
1
You can access your wp_users table using WP_User_Query.
http://codex.wordpress.org/Class_Reference/WP_User_Query
For example:
$author_query = new WP_User_Query();
// Get the results
$authors = $author_query->get_results();
A more comprehensive example can be seen here: http://wpsmith.net/2012/wp/an-introduction-to-wp_user_query-class/
1
You can have as many authors as you'd like.
If the artists are not the authors of the blog posts, I would consider using a custom taxonomy instead, because it would be a more accurate model.
EDIT
As it's been pointed out in the comments, taxonomies don't have built-in meta data, and custom post types or users are sometimes easier to handle.
1
If you use code similar to setup the rewrite rules:
function ex_rewrite( $wp_rewrite ) {
$feed_rules = array(
'author/?$' => 'index.php?author_page=author_page'
);
$wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
return $wp_rewrite;
}
// refresh/flush permalinks in the dashboard if this is changed in any way
...
1
You have a couple of issues here, the main one being that your query sets posts per page to two, but the number of pages available has no relationship to your custom query. If your "Blog pages show at most" under Reading settings is set to 10, and an author only has <= 10 posts, there is no second page.
The other issue you will discover is that you're ...
1
I assume you are trying to show the role of the post's Author and not the current user viewing the author page.
assuming you are inside the loop, do the following:
//get the post author's ID
$user_id = get_the_author_meta( 'ID' ); //assume we are in The Loop
$user_obj = get_userdata( $user_id );
if( !empty( $user_obj->roles ) ){
foreach( ...
1
Change:
$user_roles = $current_user->roles;
with
$user = new WP_User( $user_id );
$user_roles = $user->roles;
and the $user_id should e the actual user id who's role you are trying to get.
Update,
Sorry i just read the author template part so try this:
//first get the current author whos page you are viewing
if(isset($_GET['author_name']))
...
1
The mistake is in your first block of code:
<?php if (have_posts()): the_post(); ?>
<h3>
<?php _e('All posts by'); ?> <?php echo get_the_author(); ?>
<span class="arrows">»</span>
</h3>
<?php while (have_posts()) : the_post();?>
You call the_post() to populate the regular ...
1
When using custom post types I got around this problem by using the following code. Of course you will need to put in the HTML for how you want it to display on your site.
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query(''); // Enter you query here
?>
<?php while ...
1
This looks like a simular issue to this one with wp-pageNavi: http://scribu.net/wordpress/wp-pagenavi/right-way-to-use-query_posts.html.
Taxonomies and archives should use 'page', not 'paged' so use that in the urls to begin with.
Then, to ensure your pagination script works in all locations you can change the way you get your $paged variable.
Something ...
1
As the Codex states for the antispambot() function:
Return Values (string) Converted email address.
You have to do one of the following:
echo antispambot( $curauth->publicemail );
// OR...
print antispambot( $curauth->publicemail );
So your full example would look like the following:
if ( ! empty( $curauth->publicemail ) )
{
echo ...
1
First, Explaining Loops
You're dealing with two kinds of "loops." The first is a loop in PHP, the second is a loop in WordPress.
Loop in PHP
kaiser gave you some code that will generate a list of authors on your site. You can iterate through this list and print information on the screen.
// Fetch an array of authors from WordPress and store it in the ...
1
Use internal/built-in classes
WP got …
the WP_User_Query class. You can easily query for users of a role and return only those fields, that you actually need.
wp_list_authors();
Example code
$authors = new WP_User_Query( array(
'role' => 'editor',
'fields' => array(
'first_name',
'last_name'
)
) );
Then ...
Only top voted, non community-wiki answers of a minimum length are eligible