Bài viết mới nhất cho wordpress

04/05/2015 Webmaster 9353 lượt xem
Lưu bài viết

Demo: Demo-bai-viet-moi-nhat

Để tạo bài viết mới nhất trong wordpress chúng ta sử dụng code sau.

- Chèn đoạn code này nới mà bạn muốn hiển thị bài viết mới nhất. Có thể chèn trong file index.php, hoặc sidebar.php

<div class="newpost">
					<h3 class="title-news">Tin mới</h3>
	<ul class="news">
					<?php $postquery = new WP_Query(array('posts_per_page' => 6));
						if ($postquery->have_posts()) {
						while ($postquery->have_posts()) : $postquery->the_post();
						$do_not_duplicate = $post->ID;
						?>
						<li>
								<a href="<?php the_permalink(); ?>"><?php thumbnails_news_hk(); ?></a>
								<h4><a href=" <?php the_permalink(); ?> " title=" <?php the_title();  ?> "><?php the_title();  ?></a></h4>								
								<div class="info">
									<span class="date"><i class="fa fa-clock-o"> </i> Đăng ngày: <?php echo get_the_date( 'd-m-Y'); ?></span>
								</div>					
						</li>
					<?php endwhile;} ?>
					<div class="clear"></div>
			</ul>
	</div>

Sau đó chèn đoạn css này vào file style.css

.newpost, .sidebar {
    float: right;
    width: 330px;
}
h3.title-news {
    background: #145EAB;
    padding: 10px 5px;
    color: #fff;
    font-family: 'hongha';
    text-transform: uppercase;
    font-size: 15px;
}
ul.news {
    padding: 10px;
    border: 1px #145EAB solid;
}
ul.news li {
  width: 100%;
  clear: both;
  padding: 9px 0px;
}
ul.news li a img {
    width: 90px;
    height: 65px;
    float: left;
    margin-right: 9px;
	padding: 1px;
	box-shadow: 0px 0px 2px #999;
}

ul.news li h4 a {
  text-decoration: none;
  font-family: hongha;
  color: #145EAB;
  text-transform: uppercase;
  font-size: 12px;
}