I am not sure which category to ask this question, wordpress, javascript or php? I have a shortcode that I use on wordpress pages that displays the author or site owners first & last name. That works on the pages but I am trying to get something to work in the template files so I can display the same info in the header.php. I can come close and know how to display the info for the current_user or logged in user but I need it to display for everyone and use the meta data from the post author instead. If this is possible I can post the code I am using now or should this be in another section on the forum? thanks!
Hi, You can use plugin's shortcode in wordpress templates. You have to just call do_shortcodes function in the header file. For further documentation. Here is the link. http://codex.wordpress.org/Function_Reference/do_shortcode
Yeah but the shortcode function I am using is the WordPress function get_the_author_meta. This function returns the desired meta data for a user. If used within The Loop, the user ID need not be specified, and the displayed data is that of the current post author. A user ID must be specified if used outside The Loop. I am using it in the header.php template file which most of the time doesn't contain loop so you must specify user ID to the get_the_author_meta function. This is the shortcode I used which works on a page or post but not in the header.php add_shortcode( 'user_name' , 'z_get_current_name' ); function z_get_current_name( $atts ){ $user_fname = get_the_author_meta('user_firstname', $user_id); $user_lname = get_the_author_meta('user_lastname', $user_id); extract( shortcode_atts( array( 'text' => null, ), $atts ) ); return '<span class="lmn_user_info lmn_user_fname">' . $text . '' . $user_fname . '</span><span class="lmn_user_lname"> ' . $user_lname . '</span>'; } It will work using do_shortcode like you mentioned if I add $user_id = get_current_user_id(); But then only displays the name if your logged in so it can get the user id, I need it to display the info from the post author. Make sense?
It is great. This is also essential that you should use right function to get details from the wordpress database. Usually, the main problem is loading speed of the website decrease, when you do it incorrectly. It is good that you have found the solution. Keep an eye on speed optimization. <?php the_author(); ?> You can use this function to display author of a post. Additional parameter is post id. You can pass within this function. Optimize speed and improve usage of functions will result in healthier website.
does wordpress allow PHP code so your header would only need to be $_SESSION['first_name'] = $_POST['first_name']; $_SESSION['last_name'] = $_POST['last_name']; if($_SESSION['last_name']){ echo "Hello " . $_SESSION['first_name'] . " " . $_SESSION['last_name']; }
This is what I used since each site only has one admin/user/post_author: function z_show_current_name(){ // Get the current admin user, using it's registered email as key $user_info = get_user_by( 'email', get_option('admin_email')); // Use the user_info found to distill the info wanted $user_fname = $user_info->first_name; $user_lname = $user_info->last_name; // Return the output to show return '<span class="lmn_user_info lmn_user_fname">' . $user_fname . '</span><span class="lmn_user_lname"> ' . $user_lname . '</span>'; } then this in the template: <?php echo z_show_current_name(); ?>
i have also a question,how to install wordpress my local server? most of the time i spent for install warm server,but i can't successfully install it, my have a website related free wordpress theme