Undefined variable notice

时间:2015-08-19 作者:Gian Aguilar
function custom_content_filter_the_content( $content ) {

$colorsList = array(
    \'Baby Blue\' => "66CCFF",
    \'Beige\' => "CC9966",
    \'Black\' => "000000",
    \'Blue\' => "0000CC",
    \'Blush\' => "FF9999",
    \'Brown\' => "663300",
    \'Burgundy\' => "660000",
    \'Champagne\' => "FFFFCC",
    \'Coral\' => "FF6666",
    \'Cream\' => "FEE5A4",
    \'Dust Blue\' => "6699CC",
    \'Emerald\' => "006600",
    \'Fuchsia\' => "FF00CC",
    \'Gold\' => "CFB53B",
    \'Gray\' => "999999",
    \'Green\' => "339900",
    \'Lavender\' => "EAD3FF",
    \'Lime\' => "00FF33",
    \'Maroon\' => "800000",
    \'Mint\' => "80FEA5",
    \'Navy\' => "000066",
    \'Orange\' => "FF3300",
    \'Peach\' => "F4A17D",
    \'Pink\' => "F96EAE",
    \'Purple\' => "990099",
    \'Red\' => "FF0000",
    \'Seafoam\' => "66CC99",
    \'Silver\' => "CCCCCC",
    \'Teal\' => "008080",
    \'Turquoise\' => "34DDDD",
    \'Violet\' => "330099",
    \'White\' =>  "FFFFFF",
    \'Yellow\' => "FFFF00"
);
$styles = get_the_term_list( $post->ID, \'styles\', \'<li>\', \'</li><li>\', \'</li>\' );
$venues = get_the_term_list( $post->ID, \'venues\', \'<li>\', \'</li><li>\', \'</li>\' );
$colors = get_the_terms(   $post->ID, \'colors\' );

if (!empty($styles) || !empty($venues) || !empty($colors)):
$content .=
    \'<div class="style-guide clearfix" data-equalizer>
       <h3 class="the_look">The Look</h3>

    <div class="guide" data-equalizer-watch>
      <h4>Styles</h4>
        <ul class="styles">
          \'.$styles.\'
      </ul>
    </div>

    <div class="guide" data-equalizer-watch>
      <h4>Venues</h4>
        <ul class="venues">
        \'.$venues.\'
        </ul>
    </div>

    <div class="guide color-list" data-equalizer-watch>
      <h4>Colors</h4>\';
        if(!empty($colors)):
        $content .= \'<ul class="colors">\';
        foreach($colors as $color)
        {
            $link = get_term_link( $color );
            foreach($colorsList as $key => $list)
            {
                if(strtolower($key) == strtolower($color->name))
                {
                    $content .= \'<li class="color"><a href="\'.$link.\'"><span class="circle" style="background-color: #\'.$list.\'">&nbsp;</span></a></li>\';
                }
            }
        }
        $content .= \'</ul>\';
        endif;
        $content .= \'</div></div>\';
        endif;
        return $content; }
add_filter( \'the_content\', \'custom_content_filter_the_content\' );
1 个回复
最合适的回答,由SO网友:jzatt 整理而成

你得到它是因为$post 未设置变量。你需要打电话global $post 在函数的开头。

function custom_content_filter_the_content( $content ) {
    global $post;
    ...

结束

相关推荐

How to Use PHP Code In-Page?

我希望创建一个动态添加到购物车按钮。问题是,我需要我的服务器动态创建“添加到购物车”URL。目前,我构建了一个静态示例here at this link. 你会注意到页面底部有一个按帖子付费功能,还有一个“解锁全文”按钮。我想将此按钮用作“添加到购物车”按钮。到目前为止,我遇到的唯一问题是如何动态创建正确的URL扩展?以下是静态URL:https://example.com/insider/?add-to-cart=**2634**该帖子ID需要根据页面动态创建。我想试试这个:https://exampl