- 다음 코드를
functions.php
파일이나 적절한 테마 파일에 추가합니다.
global $wpdb;
// 망보드 게시판 게시물 테이블 이름
$table_posts = $wpdb->prefix . "mb_post";
$table_boards = $wpdb->prefix . "mb_board";
// 모든 게시판의 최근 게시물 가져오기 쿼리
$query = $wpdb->prepare("
SELECT p.*, b.board_name
FROM $table_posts p
JOIN $table_boards b ON p.board_id = b.board_id
ORDER BY p.regdate DESC
LIMIT %d
", $post_count);
$recent_posts = $wpdb->get_results($query);
// 게시물 출력
if (!empty($recent_posts)) {
echo '<ul class="mangboard-all-recent-posts">';
foreach ($recent_posts as $post) {
$title = esc_html($post->title);
$board_name = esc_html($post->board_name);
$url = esc_url(home_url("/mangboard/view?board_id={$post->board_id}&id={$post->id}"));
echo "<li>[{$board_name}] <a href='{$url}'>{$title}</a></li>";
}
echo '</ul>';
} else {
echo '<p>No recent posts found.</p>';
}
}
2. 테마 파일(예:
sidebar.php
또는 page.php
)에 아래 코드를 추가하여 모든 게시판의 최근 게시물을 출력합니다.3. CSS
.mangboard-all-recent-posts {
list-style: none;
padding: 0;
margin: 0;
}
.mangboard-all-recent-posts li {
margin-bottom: 10px;
}
.mangboard-all-recent-posts li a {
color: #0073aa;
text-decoration: none;
}
.mangboard-all-recent-posts li a:hover {
text-decoration: underline;
}