php - How do I link to authors post outside of the loop in wordpress -


i using ubermenu , have been helpful, have not been able figure out.

they have shortcode display recent post in menu image , title.

i want add author of post under title linked authors post.

here current code:

function ubermenu_recent_posts($atts){  global $ubermenu;  extract(shortcode_atts(array(     'num'       =>  3,           'img'       =>  'on',     'img_width' =>  85,     'img_height'=>  55,     'excerpt'   =>  'off',     'category'  =>  '',     'default_img' => false,     'offset'    =>  0,  ), $atts));  $args = array(     'numberposts'   =>  $num,     'offset'        =>  $offset,     'suppress_filters' => false );  if(!empty($category)){     if(is_numeric($category)){         $args['category'] = $category;     }     else $args['category_name'] = $category;         }  $posts = get_posts($args);   $class = 'wpmega-postlist'; if($img == 'on') $class.= ' wpmega-postlist-w-img';  $html= '<ul class="'.$class.'">'; foreach($posts $post){      $ex = $post->post_excerpt;     if( $ex == '' && function_exists( 'wp_trim_words' ) ){  //wp_trim_words wp3.3 function         $ex = $post->post_content;         $ex = strip_shortcodes( $ex );          $ex = str_replace(']]>', ']]&gt;', $ex);         $excerpt_length = apply_filters('excerpt_length', 10);         $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');         $ex = wp_trim_words( $ex, $excerpt_length, $excerpt_more );     }     //$ex = apply_filters('get_the_excerpt', $post->post_excerpt);      $post_url = get_permalink($post->id);     $author_name = get_the_author_meta('display_name', $post->post_author );     $author_id = $post->post_author;     $post_comments = comments_popup_link( __('no comments', 'wellthemes'), __( '1 comment', 'wellthemes'), __('% comments', 'wellthemes'));       $image = '';     $w = $img_width;     $h = $img_height;      if($img == 'on') $image = $ubermenu->getpostimage($post->id, $w, $h, $default_img);      $html.= '<li>'. $image.                 '<div class="wpmega-postlist-title">                 <div class="wpmega-post-title"><a href="'.$post_url.'">'.$post->post_title.'</a></div>                 <div class="wpmega-post-author"><a href="'.get_author_posts_url($author_id).'"><span>by '.$author_name.'</span></a>'.$post_comments.'</div>                 </div>';      if($excerpt == 'on')         $html.= '<div class="wpmega-postlist-content">'.$ex.'</div>';      $html.=     '<div class="clear"></div>'.             '</li>'; } $html.= '</ul>';  return $html; } add_shortcode('wpmega-recent-posts', 'ubermenu_recent_posts');  //legacy add_shortcode('ubermenu-recent-posts', 'ubermenu_recent_posts'); 

if mouse on sports menu tab , mouseover author name while on home page see links correctly, if click other page if removes author fro url.

site: http://mystreetlife.com/home


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -