我正在使用过滤器将项目仅附加到一个页面上的内容。除了$整变量的排序之外,它完全可以工作。标题显示在内容之后,但无论顺序如何,for-each循环都显示在内容的上方或前面。我想我使用one($arr)正确地通过了循环,但我仍在学习php。我通常会在页面模板中包含这种类型的循环,但我正在尝试使用插件添加它。
function insertLoop($content) {
if( is_page( \'regular-page\' ) ) {
function one( $arr ) {
global $post;
$args = array(
\'post_type\' => \'custom-post-type\',
\'posts_per_page\' => -1,
);
$customposts = get_posts( $args );
foreach ( $customposts as $post ) : setup_postdata( $post ); ?>
<div class="custom-post-listing">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<p><?php the_date(); ?></p>
</div>
<?php endforeach; wp_reset_postdata();
}
$words = "<h2>Custom Post Full List</h2>";
$whole = $content . $title . one($arr);
return $whole;
}
}
add_filter (\'the_content\', \'insertLoop\');