프리미엄 WP 테마 플러그인 무료 다운로드

Reply To: bbpress로 만든 게시판입니다

질문 제출 Forums Reply To: bbpress로 만든 게시판입니다


Word Cracker
Keymaster

카테고리 내의 총 글 개수 중 몇 번째인지를 표시하는 코드

// Fetch all posts in the current post’s (main) category
$args = array(
‘post_type’ => ‘post’,
‘posts_per_page’ => -1,
‘cat’ => array_shift(get_the_category())->cat_ID,
);
$query = new WP_Query($args);

// The index of the current post in its (main) category
$X = 1;
$id = get_the_ID();
foreach ($query->posts as $cat_post)
if ($id != $cat_post->ID)
$X++;
else
break;

// The number of posts in the current post’s (main) category
$Y = $query->found_posts;

// Now, display what we got…
echo $X.’/’.$Y;

*****
It seems that it does not work… (Reference: https://wordpress.org/support/topic/show-post-number#post-1294235 )