Membuat Perulangan Bersarang (Nested Loop) Topic pada BBpress
Kali ini saya akan berbagi tutorial bagaimana cara membuat perulangan bersarang (Nested Loop) 'Topic' pada BBpress. Kadang kali saat kita (saya juga tentunya hehehehe) menggunakan plugin BBpress pada Wordpress mdnemui beberapa kendala. Seperti pengalaman saya beberapa hari yang lalu adalah mengubah tampilan topic default BBpress menjadi seperti artikel. Kurang lebih tampilan topic view defaultnya seperti ini :Nah dari situ saya menggubah script pada file content-single-forum.php (terletak pada direktori plugins/bbpress/bbp-theme-compat/content-single-forum.php). Perlu diketahui bahwa Wordpress yang saya
pakai adalah Wordpress versi 3.4.2 dan plugin BBpress yang saya pakai adalah BBpress versi 2.1.2.
Script default :
<?php
/*** Single Topic Content Part
*
* @package bbPress
* @subpackage Theme
*/
?>
<div id="bbpress-forums">
<?php bbp_breadcrumb(); ?>
<?php do_action( 'bbp_template_before_single_forum' ); ?>
<?php if ( post_password_required() ) : ?>
<?php bbp_get_template_part( 'form', 'protected' ); ?>
<?php else : ?>
<?php bbp_single_forum_description(); ?>
<?php if ( bbp_get_forum_subforum_count() && bbp_has_forums() ) : ?>
<?php bbp_get_template_part( 'loop', 'forums' ); ?>
<?php endif; ?>
<?php if ( !bbp_is_forum_category() && bbp_has_topics() ) : ?>
<?php bbp_get_template_part( 'pagination', 'topics' ); ?>
<?php bbp_get_template_part( 'loop', 'topics' ); ?>
<?php bbp_get_template_part( 'pagination', 'topics' ); ?>
<?php bbp_get_template_part( 'form', 'topic' ); ?>
<?php elseif ( !bbp_is_forum_category() ) : ?>
<?php bbp_get_template_part( 'feedback', 'no-topics' ); ?>
<?php bbp_get_template_part( 'form', 'topic' ); ?>
<?php endif; ?>
<?php endif; ?>
<?php do_action( 'bbp_template_after_single_forum' ); ?>
</div>
Nah sekarang akan saya tuliskan script php untuk mengubah tampilan seperti artikel :)
<?php
/**
* Single Topic Content Part
*
* @package bbPress
* @subpackage Theme
*/
?>
<?php if ( bbp_has_topics() ) while ( bbp_topics() ) : bbp_the_topic(); ?>
<?php get_template_part( 'pagination', 'bbp_topics' ); ?>
<article class="bbp-note-block entry post">
<div class="note">
<div class="note-inner">
<div class="bbp-note-content">
<div class="post-title">
<span class="post-meta">
<?php esc_html_e('Posted','DailyJournal'); ?> <?php esc_html_e('on','DailyJournal'); ?> <?php the_date(); ?> <?php esc_html_e('by','DailyJournal'); ?> <?php the_author(); ?>
</span>
<h2 class="main_title"><?php bbp_topic_title(); ?></h2>
</div>
<div class="post-content clearfix">
<?php if (!$et_ptemplate_blogstyle) { ?>
<p><?php truncate_post(550);?></p>
<center><a href="<?php the_permalink(); ?>" class="readmore">
<span>
<?php esc_html_e('read more','DailyJournal'); ?></span></a></center>
<?php } else { ?>
<?php
global $more;
$more = 0;
?>
<?php bbp_topic_content(); ?>
<?php } ?>
</div>
</div>
</div>
</div>
<div class="note-bottom-left">
<div class="note-bottom-right">
<div class="note-bottom-center"></div>
</div>
</div>
<?php get_template_part( 'pagination', 'bbp_topics' ); ?>
</article>
<?php endwhile; ?>
/**
* Single Topic Content Part
*
* @package bbPress
* @subpackage Theme
*/
?>
<?php if ( bbp_has_topics() ) while ( bbp_topics() ) : bbp_the_topic(); ?>
<?php get_template_part( 'pagination', 'bbp_topics' ); ?>
<article class="bbp-note-block entry post">
<div class="note">
<div class="note-inner">
<div class="bbp-note-content">
<div class="post-title">
<span class="post-meta">
<?php esc_html_e('Posted','DailyJournal'); ?> <?php esc_html_e('on','DailyJournal'); ?> <?php the_date(); ?> <?php esc_html_e('by','DailyJournal'); ?> <?php the_author(); ?>
</span>
<h2 class="main_title"><?php bbp_topic_title(); ?></h2>
</div>
<div class="post-content clearfix">
<?php if (!$et_ptemplate_blogstyle) { ?>
<p><?php truncate_post(550);?></p>
<center><a href="<?php the_permalink(); ?>" class="readmore">
<span>
<?php esc_html_e('read more','DailyJournal'); ?></span></a></center>
<?php } else { ?>
<?php
global $more;
$more = 0;
?>
<?php bbp_topic_content(); ?>
<?php } ?>
</div>
</div>
</div>
</div>
<div class="note-bottom-left">
<div class="note-bottom-right">
<div class="note-bottom-center"></div>
</div>
</div>
<?php get_template_part( 'pagination', 'bbp_topics' ); ?>
</article>
<?php endwhile; ?>
Tadaaa!!! Setelah diubah script single-content-forum.php-nya seperti tadi tampilan topik BBpress akan berubah menjadi seperti ini nantinya :
Related :
BBpress
Wordpress
BBpress shortcode


0 komentar: