2016-11-29 36 views
0

以下代码只适用于访问者,但如果我用socials-links.php内容替换include(),它对访问者和用户都正常工作。那么,include()有什么问题。 下面是代码:为什么此功能仅适用于访客?

function render_social_links() { 
$current_post_id=get_the_ID(); 
$them_uri = get_stylesheet_directory_uri(); 
$featured_image_url = ''; 
if (has_post_thumbnail($current_post_id)) { 
    $featured_image_id = get_post_thumbnail_id($current_post_id); 
    $featured_image_url = $featured_image_id ? wp_get_attachment_url($featured_image_id) : ''; 
} 
if(is_home() || is_single()){ 
     if(is_home()){ 
     $bitlink = $lnk = get_bloginfo('url'); 
     $bitly = getBitly($bitlink); 
     $nam = get_bloginfo('name'); 
     } 
     elseif(is_single($current_post_id)){ 
      $bitlink = $lnk = get_permalink($current_post_id); 
      $bitly = getBitly($bitlink); 
      $nam = get_the_title($current_post_id); 
     } 
     $bitlink =esc_url($bitlink); 
     $lnk = esc_url($lnk); 
     $nam= esc_attr($nam); 
     $bitly = esc_url($bitly); 
     include($them_uri.'/social-links.php'); 
     } 

    } 

这里是社会links.php内容:

<div id="socialleft"> 
    <ul> 
     <li> 
     <img src="'.$them_uri.'/images/social/share-38.png" alt=""/> 
     </li> 
    <li> 
      <a href="http://www.facebook.com/sharer.php?u='.$lnk.'&amp;t='.$nam.'" title="شارك على فيسبوك" target="_blank"> 
     </li> 
      <img src="'.$them_uri.'/images/social/facebook-38.png" alt="" /> 
      </a> 
     </li> 
     <li> 
     <a href="http://twitter.com/home/?status='.$nam.' : '.$bitly.'" title="غرد" target="_blank"> 
     <img src="'.$them_uri.'/images/social/twitter-38.png" alt="" /> 
     </a> 
    </li> 
    <li> 
    <a href="https://plus.google.com/share?url='.$lnk.'" onclick="javascript:window.open(this.href,\'\', \'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=60\');return false;" title="شارك على جوجل+" target="_blank"> 
<img src="'.$them_uri.'/images/social/Google-plus-38.png" alt="" /> 
     </a> 
    </li> 
    </ul> 
</div> 

和CSS social_links.php相关:

#socialleft{ 
    position:fixed; 
    top: 35%; 
    left: 0; 
    height:100%; 
    width:45px; 
    margin-left:15px; 
    display:block; 
    z-index:100; 
    transition: width ease .5s;  
    } 
+0

那么,问题在哪里,你现在想要什么? –

+0

问题是Include使得输出仅对访问者可用,但是当我(管理员)或其他用户登录时,则没有output.that是我所问的,为什么会发生这种情况? –

+0

请启用调试并检查 –

回答

0

在这种情况下,有管理员包含文件中的一个条件

include($them_uri.'/social-links.php'); 

您的代码在条件标签内进行了扭曲。

if (!is_admin()): 

end if; 
+0

该文件存在于子主题内,这就是为什么我使用'get_stylesheet_directory_uri();'它已经加载但只限于未登录用户的访问者 –

+0

共享文件social-links.php –

+0

没有在条件标签内变形,因为如果是这样,至少它应该为管理员工作,但它仅适用于访问者 –

相关问题