【发布时间】:2018-12-29 09:20:42
【问题描述】:
我创建了一个简单的自定义插件,可以将帖子分组:
function custom_category_loop()
{
// Grab all the categories from the database that have posts.
$categories = get_terms( 'category', 'orderby=name&order=ASC');
// Loop through categories
foreach ( $categories as $category )
{
// Display category name
echo '<h2 class="post-title">' . $category->name . '</h2>';
echo '<div class="post-list">';
// WP_Query arguments
$args = array(
'cat' => $category->term_id,
'orderby' => 'term_order',
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() )
{
while ( $query->have_posts() )
{
$query->the_post();
?>
<div><a href="<?php the_permalink();?>"><?php the_title(); ?></a></div>
<?php
} // End while
} // End if
echo '</div>';
// Restore original Post Data
wp_reset_postdata();
} // End foreach
}
add_shortcode( 'my_posts_grouped', 'custom_category_loop' );
然后我创建了一个页面并添加了单行
[my_posts_grouped]
我的 WordPress 安装是多站点安装,所有页面都使用相同的主题,因为我有相同的站点但使用不同的语言(和 URL)。
我的问题是,在我所有的网站上,除了一个网站,简码都能完美运行。仅在一个站点上,代码在页眉之前和正文页内输出。
任何想法为什么以及如何解决这个问题?
【问题讨论】:
-
那个网站的代码/标记有什么不同?