Php 如何解决内容过滤器的问题
我想在\u内容之后添加包含自定义帖子信息的快捷码,但在添加代码时,它会显示在\u内容之前 这是我的密码Php 如何解决内容过滤器的问题,php,wordpress,shortcode,Php,Wordpress,Shortcode,我想在\u内容之后添加包含自定义帖子信息的快捷码,但在添加代码时,它会显示在\u内容之前 这是我的密码 <?php function foobar_func() { ?> <h3>Title : </h3> <ul> <li>foo : </li> </ul> <?php } add_shortcode( 'project_information', 'foobar_func'
<?php
function foobar_func() { ?>
<h3>Title : </h3>
<ul>
<li>foo : </li>
</ul>
<?php }
add_shortcode( 'project_information', 'foobar_func' );
function wpdev_before_after( $content ) {
$beforecontent = '';
if ( is_single() ) {
$aftercontent = '[project_information]';
} else {
$aftercontent = '';
}
$fullcontent = $beforecontent . $content . $aftercontent;
return $fullcontent;
}
add_filter('the_content', 'wpdev_before_after');
?>
标题:
- 傅:
我的foobar_func应该是这样的,我有更多自定义分类法要列出,如果我使用变量来显示它们,我的代码将非常混乱
function foobar_func() { ?>
<h3>Title : </h3>
<ul>
<li>foo : <?php
$terms = wp_get_post_terms( $post->ID, 'taxonomy', $args );
foreach( $terms as $term ) {
if ( end($terms) == $term ){
echo '<a href="' . esc_url( get_term_link( $term ) ) . '" title="' . esc_attr( sprintf( __( '%s', 'tiads' ), $term->name ) ) . '">' . $term->name . '</a>';
} else {
echo '<a href="' . esc_url( get_term_link( $term ) ) . '" title="' . esc_attr( sprintf( __( '%s', 'tiads' ), $term->name ) ) . '">' . $term->name . '</a> , ';
}
}
?></li>
</ul>
<?php }
函数foobar\u func(){?>
标题:
- 傅:
尝试将html分配给变量,并将其返回到foobar\u func()
函数foobar_func(){
$html=”
标题:
- 傅:
";
$terms=wp\u get\u post\u terms($post->ID,'taxonomy',$args);
foreach($terms作为$term){
如果(结束($terms)=$term){
$html.='';
}否则{
$html.=',';
}
}
$html.=”
”;
返回$html;
}
我不能将它们存储在变量中,因为我需要在我的快捷键中使用一些查询。即使需要运行查询和输入数据,您也应该能够返回变量?您能准确地发布代码吗?请查看我的更新答案,这将提供与之前完全相同的结果,但会放入变量中。
function foobar_func() {
$html = "
<h3>Title : </h3>
<ul>
<li>foo :
";
$terms = wp_get_post_terms( $post->ID, 'taxonomy', $args );
foreach( $terms as $term ) {
if ( end($terms) == $term ){
$html .= '<a href="' . esc_url( get_term_link( $term ) ) . '" title="' . esc_attr( sprintf( __( '%s', 'tiads' ), $term->name ) ) . '">' . $term->name . '</a>';
} else {
$html .= '<a href="' . esc_url( get_term_link( $term ) ) . '" title="' . esc_attr( sprintf( __( '%s', 'tiads' ), $term->name ) ) . '">' . $term->name . '</a> , ';
}
}
$html .= "
</li>
</ul>";
return $html;
}