2012-07-31 40 views
0

我最近在wordpress博客中安裝了一個新模板(更具體地說是SquirrelTheme - 一個免費模板)。碰巧我想在我的首頁上有兩個按鈕。比方說按鈕X和按鈕Y.爲了創建這些按鈕,我使用了一個名爲「MaxButtons」的插件,它允許您輕鬆創建和管理按鈕及其功能。創建該按鈕後,它會給你一個簡碼,你可以在你的帖子和頁面中插入 - 可以說[maxbutton id =「1」] - 來顯示它。如何強制wordpress模板解析代碼而不是純文本

不幸的是,在根據我的喜好編輯模板(刪除了我不打算顯示的div)之後,我似乎無法顯示這兩個按鈕,因爲模板解析純文本,顯然不同於pages/posts。

如果您想知道如何爲按鈕插入短代碼,可以通過儀表板輕鬆修改該模板,其中我在該字段中插入以下內容,該字段指示在我的主頁的特定部分上顯示的內容:

[maxbutton id="1"] [maxbutton id="2"] 

就像我之前說的,而不是顯示爲預期的按鈕,我只看到正是我在框中鍵入。

我相信這是由模板如何解析文本,因爲它使用其自身的功能引起的( - PHP _e(「...」)?)來呼應全文:

<div class="full_content"> 
    <center> 
    <?php if (squirrel_get_option('squirrel_slidehead') != '') { ?> 
     <h1><?php echo stripslashes(squirrel_get_option('squirrel_slidehead')); ?></h1> 
    <?php } else { ?> 
     <h1><?php _e('We are scope, a design firm in England', 'squirrel'); ?></h1> 
    <?php } ?>    
    <?php if (squirrel_get_option('squirrel_slidedesc') != '') { ?> 
     <h2><?php echo stripslashes(squirrel_get_option('squirrel_slidedesc')); ?></h2>    
    <?php } else { ?> 
     <p><?php _e('Newfoundland dogs are good to save children from drowning, but you must have a pond of water handy and a child.', 'squirrel') ?></p> 
     <p><?php _e('From drowning, but you must have a pond of water handy and a child.', 'squirrel'); ?></p> 
    <?php } ?> 
    </center>  
    </div> 

我的問題是,我怎樣才能讓它顯示按鈕或任何其他代碼。

在此先感謝。

回答

2

您可以調用函數do_shortcode()對某些文本執行正確的shortcode處理。

例子:

echo do_shortcode('This is a button: [maxbutton id="1"]'); 
+0

感謝您在我的文字的牆閱讀和回覆,以便快速,準確地:)我有一個問題,雖然,如果你不介意ofcourse回覆。我如何顯示一個按鈕旁邊的按鈕?因爲如果我這樣做「<?php echo do_shortcode('這是一個按鈕:[maxbutton id =」1「] [maxbutton id =」2「]');?>」它只會顯示一個按鈕另一個。再次感謝你:) – user1298923 2012-07-31 13:49:01

+0

@ user1298923:這很難說沒有看到生成的HTML。但是,在另一個問題中可能值得提問。 – 2012-07-31 13:51:38

+0

好的,謝謝:) – user1298923 2012-07-31 13:54:32