2016-11-29 74 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

沒有在條件標籤內變形,因爲如果是這樣,至少它應該爲管理員工作,但它僅適用於訪問者 –

相關問題