我不知道到底哪里出了问题,但我想发生的是,我动态获取的类别不是基于BuddyPress组slug(帖子类别有匹配的名称)被转换为整数而不是字符串,因此不会循环它们。
function chapter_posts() {
//Get Group Slug
$chapterSlug = bp_get_current_group_slug();
$chapterCatID = get_cat_id( $chapterSlug );
//Get posts
global $post;
$args = array(
\'cat\' => \'$chapterCatID,15\',
\'posts_per_page\' => 5
);
$posts = get_posts( $args ); ?>
<div class="group_post_start">
<ul>
<?php
foreach( $posts as $post ): setup_postdata($post);
?>
<li>
<a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><h2><?php the_title(); ?></h2></a>
<div class="group_post_display">
<p><?php the_excerpt(); ?></p>
<p><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>" class="button">Read More</a></p>
</div>
</li>
<?php
endforeach;
wp_reset_postdata(); // reset the query ?>
</ul>
</div><!--.group_post_start-->
<div class="group_post_end">
<a href="<?php echo get_site_url();?>/blog/category/mompreneurs/<?php echo $postCategory; ?>/" class="button">More</a>
</div><!--.group_post_end-->
<?php
}
add_action( \'bp_before_group_home_content\', \'chapter_posts\', 50);
在每一个BuddyPress组页面上,我都想显示主帖子类别(ID=15)和其slug与BP组slug匹配的类别的混合。
为了验证这一点,我要做的是找到一个地方,基本上呼应出$chapterCatID在我这样做时的结果:
<?php echo $chapterCatID; ?>
。。。它总是以0结尾,根据法典,这是一个失败。所以我需要知道的是,如何将get\\u cat\\u id()函数的结果保留为字符串?
SO网友:Tony Djukic
所以,我想我已经弄明白了。。。get\\u cat\\u ID似乎不是正确的函数。我将其与get\\u category\\u by\\u slug进行了交换,最终使其启动并运行。
//LINK IN BLOG POSTS THAT MATCH CHAPTER SLUG
function chapter_posts() {
//Get Group Slug
$postCategory = bp_get_current_group_slug();
//Get posts
global $post;
$chapterCatID = get_category_by_slug($postCategory)->term_id;
$args = array(
\'cat\' => \'\'. $chapterCatID . \',15\',
\'posts_per_page\' => 4
);
$posts = get_posts( $args ); ?>
<div class="group_post_start">
<ul>
<?php
foreach( $posts as $post ): setup_postdata($post);
?>
<li>
<a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><h2><?php the_title(); ?></h2></a>
<div class="group_post_display">
<p><?php the_excerpt(); ?></p>
<p><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>" class="button">Read More</a></p>
</div>
</li>
<?php
endforeach;
wp_reset_postdata(); // reset the query ?>
</ul>
</div><!--.group_post_start-->
<div class="group_post_end">
<a href="<?php echo get_site_url();?>/blog/category/mompreneurs/<?php echo $postCategory; ?>/" class="button">More</a>
</div><!--.group_post_end-->
<?php
}
add_action( \'bp_before_group_home_content\', \'chapter_posts\', 50);