2015-07-20 114 views
0

我已經下載了一些插件來呈現我的網站內的YouTube搜索,短代碼完美工作在網頁/帖子上,但是當我在index.php上使用<?php echo do_shortcode('[soundcloud_wpress]');?>時,它沒有顯示任何內容。短代碼不能在index.php上工作

的index.php:

<?php 
/** 
* The main template file 
* 
* This is the most generic template file in a WordPress theme 
* and one of the two required files for a theme (the other being style.css). 
* It is used to display a page when nothing more specific matches a query. 
* e.g., it puts together the home page when no home.php file exists. 
* 
* Learn more: {@link https://codex.wordpress.org/Template_Hierarchy} 
* 
* @package WordPress 
* @subpackage Twenty_Fifteen 
* @since Twenty Fifteen 1.0 
*/ 

get_header(); ?> 

    <div id="primary" class="content-area"> 
     <main id="main" class="site-main" role="main"> 

      <div class="row searchdiv-wrapper"> 

       <div class="col-sm-6 youtube-search"> 

       <?php echo do_shortcode('[youtube_wpress]');?> 
       </div> 
       <div class="col-sm-6 soundcloud-search"> 

         <?php echo do_shortcode('[soundcloud_wpress]');?> 

       </div> 

      </div> 
     </main><!-- .site-main --> 
    </div><!-- .content-area --> 

<?php get_footer(); ?> 

的插件添加簡碼:

$GLOBALS['ygp_youtube_wpress'] = get_option('ygp_youtube_wpress'); 
$GLOBALS['ygp_youtube_wpress']['plugin_code'] = 'youtube_wpress'; 
$GLOBALS['ygp_youtube_wpress']['item_name'] = 'youtube_wpress'; 

//error_reporting(E_WARNING); 

require_once dirname(__FILE__).'/include/vbox/include/webzone.php'; 
require_once dirname(__FILE__).'/activation.php'; 

$a1=new Youtube_wpress_activation(); 
if($a1->verify_activation()) { 
    require_once dirname(__FILE__).'/youtube_widget.php'; 
} 

if(is_admin()) { 
    require_once dirname(__FILE__).'/admin/options.php'; 
} 

class Youtube_wpress { 

    function Youtube_wpress() { 

     if(is_admin()) { 
      register_activation_hook(__FILE__, array(__CLASS__, 'on_plugin_activation')); 
      //Settings link 
      add_filter('plugin_action_links', array(__CLASS__, 'plugin_action_links'), 10, 2); 
     } 

     //Shortcodes 
     add_shortcode('youtube_wpress', array(__CLASS__, 'youtube_wpress_shortcode')); 
    } 

    function add_scripts_wp_footer() { 

    } 

我從插件類只添加了第一頂碼。

任何想法爲什麼回聲短代碼不能只在index.php內工作?

感謝和抱歉的初學者問題。

回答

0

這裏是你應該如何使用do_shortcode()功能的一些注意事項:

<?php 
add_filter('the_content', 'do_shortcode', 11); // From shortcodes.php 

// Use shortcode in a PHP file (outside the post editor). 
echo do_shortcode(''); 

// In case there is opening and closing shortcode. 
echo do_shortcode('[iscorrect]' . $text_to_be_wrapped_in_shortcode . '[/iscorrect]'); 


// Enable the use of shortcodes in text widgets. 
add_filter('widget_text', 'do_shortcode'); 


// Use shortcodes in form like Landing Page Template. 
echo do_shortcode('[contact-form-7 id="91" title="quote"]'); 


// Store the short code in a variable. 
$var = do_shortcode(''); 
echo $var; 
?> 

有一個例外,內置嵌入短碼可與WordPress。爲了使用這個簡碼do_shortcode(),你可以做以下事情:

<?php 
$embedurl = 'http://yourembeddableurl.com'; 
if (! empty($embedurl)) { 
    $var = apply_filters('the_content', ""); 
    echo $var; 
} 
?> 
+0

嗯,這不行。當我在使用[?php echo do_shortcode('[soundcloud_wpress]')時在[posts]或page中使用[soundcloud_wpress]時如何結束? ?>裏面index.php這不工作。 – user2635001