0
今日投稿された投稿をエコーする機能が必要です。今日の投稿のみを取得しますか?
00.00から23.59。 IHAVEは、関数を作成したが、それは私がここ を必要とする結果を与えていない私の関数である。
function todayNews() {
$id = mysql_real_escape_string ($id);
$sql = 'SELECT * FROM wp_posts WHERE post_status = "publish" AND post_date = CURRENT_DATE ORDER BY post_date DESC LIMIT 15';
$res = mysql_query($sql) or die (mysql_error());
if (mysql_num_rows($res) !=0):
while ($row = mysql_fetch_assoc($res)) {
$title = ($row['post_title']);
$old_date = $row['post_date']; // returns Saturday, January 30 10 02:06:34
$old_date_timestamp = strtotime($old_date);
$new_date = date('H:i', $old_date_timestamp);
$mycontent = ($row['post_content']);
$mycontent = strip_tags($mycontent);
$mycontent = substr($mycontent,0,350);
$mycontent = preg_replace("/\[caption.*\[\/caption\]/", '', $mycontent);
$first_img = '';
$my1content = $row['post_content'];
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $my1content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/img/default.png";
}
echo '
<ul class="li-sub">
<li>
'.$title.'
</li>
</ul>
';
}
else:
echo 'There are no posts for today !';
endif;
} // end
ありがとうございました!
EDIT: Post_dateは、この形式を持っている:Y-M-DのH:私は
あなたは何を得ていますか、何を得ようとしていますか? –
あなたのテーブルに 'post_date'という列のタイプはありますか?データはどのように保存されていますか? – jprofitt
こんにちは私はpost_date形式について自分の投稿を編集しました! – Meo