使用内容筛选器添加Metabox值

时间:2014-08-16 作者:ashraf

我能够在索引和单个帖子上显示转发器元盒。现在我想用

add_filter( \'the_content\', \'theme_slug_filter_the_content\' );
获取元值的我的代码

<?php
$data = get_post_meta($post->ID,"repeatable_fields",true);
echo \'<ul>\';
if (count($data) > 0){
    foreach((array)$data as $p ){
        if (isset($p[\'name\']) || isset($p[\'select\'])|| isset($p[\'url\'])){
            echo \'<li>Number: \'.$p[\'name\'].\' Description: \'.$p[\'select\'].\' Price: \'.$p[\'url\'].\'</li>\';
        }
    }
}
echo \'</ul>\';
?>
我想我的代码是

function theme_slug_filter_the_content( $content ) {
$custom_content = \'YOUR CONTENT GOES HERE\';
$custom_content .= $content;
return $custom_content;
}
add_filter( \'the_content\', \'theme_slug_filter_the_content\' );

1 个回复
最合适的回答,由SO网友:Sadia Mehjabin 整理而成

你试过这个吗?希望这能奏效。

add_filter( \'the_content\', \'cd_display_quote\' );
function cd_display_quote( $content )
{   
// We only want this on single posts, bail if we\'re not in a single post
// if( !is_single() ) return $content;

// We\'re in the loop, so we can grab the $post variable
global $post;


$data = get_post_meta($post->ID,"repeatable_fields",true);
echo \'<ul>\';
if (count($data) > 0){
    foreach((array)$data as $p ){
        if (isset($p[\'name\']) || isset($p[\'select\'])|| isset($p[\'url\'])){
            echo \'<li>Number: \'.$p[\'name\'].\' Description: \'.$p[\'select\'].\' Price: \'.$p[\'url\'].\'</li>\';
        }
    }
}
echo \'</ul>\';

// Return the values: quote first, then the content
return $content;
 }

结束

相关推荐

WPAlChemy Metabox重写插件

所以我的问题是:我创建了一个名为“项目”的自定义帖子类型。我已经通过WPAlchemy成功添加了几个代谢组。这些很好用。我遇到的问题是,当我为相关项目创建带有复选框的元框时,我可以使用复选框列出所有项目标题,但当我至少选择一个并保存自定义帖子时,它会重写Slug。我想是因为我打电话<?php the_title(); ?>. 下面是我的meta PHP文件代码:<div class=\"my_meta_control\"> <p>Add or subt