【问题标题】:ShortCode Wordpress doesnt work简码 Wordpress 不起作用
【发布时间】:2014-01-11 15:57:30
【问题描述】:

我在帖子中放了一个简码,但由于某种原因它没有执行。这是我的代码:

short-code.php:

add_shortcode('teammate',function($atts){
            $classes=$atts['country'];
            $imgUrl=$atts['img'];
            $name=$atts['name'];
            $description=$atts['description'];
            echo '
            <div class="member "'.$classes.'>
                <div class="member-img">
                    <img src="'.$imgUrl.'">
                </div>
                <div class="member-desc">
                    <h1>'.$name.'</h1>
                    <p>'.$description.'</p>
                </div>
                <div class="clear"> </div>

            </div>
            ';
        });

这是我在functions.php 中包含文件的方式:

$includes = array(
                'includes/theme-options.php',           // Options panel settings and custom settings
                'includes/theme-functions.php',         // Custom theme functions
                'includes/theme-actions.php',           // Theme actions & user defined hooks
                'includes/theme-comments.php',          // Custom comments/pingback loop
                'includes/theme-js.php',                // Load JavaScript via wp_enqueue_script
                'includes/sidebar-init.php',            // Initialize widgetized areas
                'includes/theme-widgets.php',           // Theme widgets
                'includes/short-code.php',              // Custom shortcode file for side menu
                'includes/team.php'                     //team shortcode
                );

这是我在我的页面中输入的内容:

<div class="outer-members">
        <div class="inner-members">
[teammate name="Darko Petkovski" img="http://myurl.com/myimage.jpg" description="test" country="mc"]

        </div>
        </div>

【问题讨论】:

    标签: php wordpress shortcode


    【解决方案1】:

    似乎代码工作正常,但唯一的问题是短代码没有在 wp 之外执行。

    【讨论】:

    • 嗨,首先,您的答案似乎确实是添加了有关该问题的信息,所以也许您应该将其编辑到您的问题中。其次,shortcode isn't executing outside wp 是什么意思?
    • 你的意思是在你的帖子之外,在模板文件的某个地方?
    • 我在 wp 之外有一个 html 页面,但在同一台服务器上。因此,我通过帖子 ID 获取帖子内容,然后使用 do_shortcode() 获取帖子内容,我设法让简码执行。
    猜你喜欢
    • 1970-01-01
    • 2013-03-01
    • 2015-02-01
    • 2023-01-22
    • 1970-01-01
    • 2016-07-17
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多