2012-08-27 60 views
-1

我得到解析錯誤:語法錯誤,意外「{」解析錯誤:語法錯誤,意想不到的「{」如果在()

這裏是我的代碼(在WordPress的評論循環使用)

<?php 
if (current_user_can('edit_comment',$comment->comment_ID)) { ?> 
    <a href="<?php echo get_edit_comment_link(); ?>" title="Edit Comment"> 
     <img src="<?php echo get_template_directory_uri();?>/images/edit-link.png"/> 
    </a> 
<?php } ?> 
+0

爲什麼在代碼中有兩個反引號/反引號?你在這裏發佈時添加了那些嗎? –

+0

對不起。我的錯。改爲 – user1627401

+0

是不是wordpress? – dynamic

回答

0

嘗試:

<?php if (current_user_can('edit_comment',$comment->comment_ID)) : ?> 
    <a href="<?php echo get_edit_comment_link(); ?>" title="Edit Comment"> 
     <img src="<?php echo get_template_directory_uri();?>/images/edit-link.png"/> 
    </a> 
<?php endif;?> 
+1

請勿使用短標籤。相當數量的服務器不支持,並且經常變得令人頭疼。 – Leri

+0

我也可以發誓,我用這個代碼沒有成功。但它現在正常工作..謝謝 – user1627401

-1

試試這個

<?php 
if (current_user_can('edit_comment',$comment->comment_ID)) { 
    echo "<a href=\"get_edit_comment_link()\" title=\"Edit Comment\"> 
     <img src=\"get_template_directory_uri()/images/edit-link.png\"/> 
    </a>"; 
} ?> 

也爲什麼不是

<?php $a=get_edit_comment_link(); $b=get_template_directory_uri(); 
if (current_user_can('edit_comment',$comment->comment_ID)) { 
    echo "<a href=\"$a\" title=\"Edit Comment\"> 
     <img src=\"$b/images/edit-link.png\"/> 
    </a>"; 
} ?> 
+0

像這樣回聲的HTML是一個惡夢閱讀,調試和維護。 – Furgas

+0

多次使用,每次多使用7個字節。它可能不會太多,但想象一下用戶加載100次頁面。 – MayTheSchwartzBeWithYou

+0

@Furgas我知道我只是短暫而且更容易理解。你喜歡做這個 我主要使用回聲<<< something – MayTheSchwartzBeWithYou

0

我是一個堅持一種語言的大粉絲一次。上下文切換令人困惑。

<?php 

if (current_user_can('edit_comment',$comment->comment_ID)) { 
    printf("<a href='%s' title='Edit Comment'><img src='%s/images/edit-link.php'/></a>", 
     get_edit_comment_link(), 
     get_template_directory_uri() 
    ); 
} 

?> 

雖然這是個人偏好,我沒有看到任何技術上的問題在代碼中的問題。

+0

啊,歡呼聲,另一個匿名downvote。看,如果你不喜歡答案,請發表評論,說明原因。如果它不正確*或*誤導*,請將其下載。無聲的狙擊是懦弱和毫無意義的。 – ghoti

相關問題