2016-11-15 15 views
1

私はWordPressの初心者です。Code Prettifyプラグインの使用に失敗しました

私はWordpressのSparkling Themeにコードブロックを挿入しようとしています。 これは、エディタで私のコードです:

Following is a snippet of a sample Layout file. 
<pre class="prettyprint"> 
<code class="xml"> 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TextView android:id="@+id/text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="This will print hello world" /> 

    <!-- More GUI components go here --> 

</LinearLayout> 
</code></pre> 

そして、私は出力としてこれを取得しています: Output of above code

私が間違っているの場所を教えてください。おかげでアドバンス.. :)

答えて

0

あなたはWPエディタやテーマのPHPファイルにコードブロックを挿入することを意味しますか?

ただし、まずコードをhtmlエンティティに変換する必要があります。 exmaple用:WPエディタでPHPで

<?php 
$code = '<xml>...</xml>'; 

echo '<pre><code>'; 
echo htmlentities($code); 
echo '</code></pre>'; 
?> 

は、WPが自動テキストモードでエンティティをHTMLに変換します、ビジュアルモードを経由して、あなたのコードを貼り付けます。

+0

私はWPエディタでそれをやっていますが、本当にPHPスクリプトを追加する必要がありますか? – Ashwani

+0

いいえ、wpエディタにコードを挿入したいだけなら、PHPに触れる必要はありません。 – Cl0udSt0ne

1

根本原因はxmlタグシンボルです。

変更

&lt;に変更<>これは私のために働いた &gt;

へ!

関連する問題