Plugin Advanced Custom Fields hay gọi tắt là plugin ACF được dùng cho wordpress.
1 - Tạo phần tác giả và nguồn tin cho bài viết (chưa có css)
<?php
// Hiển thị tác giả và nguồn tin
if ( get_field('tac_gia') ) { ?>
<h5 style="text-align: right;"><b><u></u> <?php the_field('tac_gia'); ?></b></h5><?php
}
if ( get_field('nguon_tin') ) { ?>
<h5 style="text-align: right;"><b><u>Nguồn:</u> <a href="<?php the_field('link_nguon_tin'); ?>" target="_blank" rel="noopener"><?php the_field('nguon_tin'); ?></a></b></h5><?php
}
?>
2 - Tạo phần tin liên quan với chọn tin trong danh sách bài viết.
Cách này chỉ việc chọn bài viết trong trang nội dung. Ở giao diện sẽ hiển thị dạng danh sách các bài viết đã chọn.
<div class="tin_lien_quan">
<?php
$featured_posts = get_field('chon_tin_lien_quan');
if( $featured_posts ): ?>
<div class="tt_tin_lien_quan">
<b>Tin liên quan</b>
</div>
<ul>
<?php foreach( $featured_posts as $featured_post ):
$permalink = get_permalink( $featured_post->ID );
$title = get_the_title( $featured_post->ID );
$custom_field = get_field( 'chon_tin_lien_quan', $featured_post->ID );
?>
<li>
<a href="<?php echo esc_url( $permalink ); ?>"><?php echo esc_html( $title ); ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
