我正在使用插件homepage control 在许多项目中,我非常喜欢它所做的。我可以为我的静态主页创建自定义部分,并可以在customizer中对它们进行排序。在我最近的客户项目中,我认为根据我主页的子页面创建此类分区是一个好主意-我完全失败了。首先,我尝试使用变量函数名,但无法使用add\\u操作访问函数。然后我尝试在add\\u操作调用中使用匿名函数,但现在我无法将内容变量传递给它。
也许我的整个方法都走错了方向,有人给我一个提示或更好的解决方案吗?
提前谢谢。
if ( ! function_exists( \'homepage_content\' ) ) {
function homepage_content() {
$the_id = 5;
$item = get_post( $the_id );
$page_tree_array = get_pages( array(
\'child_of\' => $the_id
) );
foreach( $page_tree_array as $item ) {
$id = $item->ID;
$slug = $item->post_name;
$title = apply_filters( \'the_title\', $item->post_title );
$content = apply_filters( \'the_content\', $item->post_content );
$function_name = \'homepage_section_\' . $slug;
add_action( \'homepage\', function() {
?>
<article id="post-<?php echo $id; ?>" <?php post_class( \'homepage-content\' ); ?>>
<h1><?php echo $title; ?></h1>
<?php echo $content; ?>
</article>
<?php
}, 60 );
}
}
}