如何从每个月的自定义帖子类型中获取所有帖子?
以下是我现在的表现方式,但它只显示所有标题。
<?php $news = new WP_Query( array( 'post_type' => 'notice', 'posts_per_page' => 999, 'order' => 'ASC' ) ); ?>
<?php while ( $news->have_posts() ) : $news->the_post(); ?>
<div class="testi-archive-list">
<a href="<?php the_permalink()?>"/> <h1><?php the_title()?></h1></a>
<p><?php the_field('sub_title_noticias')?></p>
</div>
<?php endwhile ?>
我想要的是这样的:
1月: 标题1 标题2
2月: 标题1 标题2
等等。有人可以帮忙吗?
答案 0 :(得分:0)
似乎没有特定的WordPress功能来执行此操作。 <!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<form class="form-inline" role="form">
<div class="form-group" id="parent_div">
<div class="row form-group" id="child_div">
<label for="day" class="col-xs-2 control-label"></label>
<div class="col-xs-12 col-lg-3">
<label for="form-input-col-xs-2" class="wb-inv">Other Job Position:</label>
<div class="input-group" style="">
<select class="form-control " id="employeetype" onchange="updateText('')">
<option value="" disabled="" selected="" >Select Job Type</option>
<option value="10">1</option>
<option value="10">2</option>
<option value="10">3</option>
</select>
</div>
</div>
<div class="col-xs-12 col-lg-3" >
<label for="form-input-col-xs-3" class="wb-inv">Date:</label>
<div class="input-group" >
<input type="text" class="form-control" id="form-input-col-xs-3" placeholder="DD/MM/YYYY" />
<span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>
</div>
<div class="col-xs-12 col-lg-3">
<label for="form-input-col-xs-4" class="wb-inv">Amount:</label>
<div class="input-group" >
<input type="text" class="form-control" id="form-input-col-xs-4" placeholder=".00" />
<span class="input-group-addon"><i class="glyphicon glyphicon-usd"></i></span>
</div>
</div>
</div>
</div>
<label for="day" class="col-xs-2 control-label"></label>
<input class="btn btn-success " type="button" id="create_button" value="+" />
</form>
</div>
<script>
document.getElementById("create_button").onclick = function (){
var temp = document.getElementById("child_div").outerHTML;
document.getElementById("parent_div").innerHTML = document.getElementById("parent_div").innerHTML + temp;
}
</script>
</body>
</html>
接近但没有雪茄。这段代码可以满足您的需求,显然您需要对其进行更改,以适应您之后的布局和风格。
wp_get_archives
答案 1 :(得分:0)
要做到这一点,您需要做的就是从当前帖子的发布日期获取当前月份和年份,然后将其与上一个帖子的发布日期,月份进行比较,然后显示日期,如果飞蛾不在如果匹配则匹配或不显示
要完成此任务,您需要:
从当前帖子的发布日期获取月份。要实现此目的,请使用get_the_time( 'F' )
使用$wp_query->posts['this will be current post -1 ']->post
在循环中获取上一篇文章。
获取并比较两个帖子之间的月份
根据比较显示或不显示日期
<?php
$news = new WP_Query( array('post_type' => array( 'notice' ),'posts_per_page' => 999, 'order' => 'ASC' ));
if( $news->have_posts() ) {
while( $news->have_posts() ) {
$news->the_post();
$current_month = get_the_date('F');
if( $news->current_post === 0 ) {
the_date( 'F Y' );
}else{
$f = $news->current_post - 1;
$old_date = mysql2date( 'F', $news->posts[$f]->post_date );
if($current_month != $old_date) {
the_date( 'F Y' );
}
}
// output data for the post
?>
<div class="testi-archive-list">
<a href="<?php the_permalink(); ?>"/> <h2><?php the_title(); ?></h2></a>
<p><?php the_field('sub_title_noticias'); ?></p>
</div>
<?php
}//End while
}
?>