2011-10-27 3 views
0

오늘 게시 된 게시물을 반향시킬 기능이 있어야합니다.오늘 게시물 만 가져 오시겠습니까?

00.00 - 23.59.

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 차원 H : 제가

+0

무엇을 얻고 있으며 무엇을 얻으려고합니까? –

+1

테이블에'post_date '열의 유형은 무엇입니까? 데이터는 어떻게 저장됩니까? – jprofitt

+0

안녕하세요, post_date 형식에 대한 내 게시물을 수정했습니다! – Meo

답변

2

넌 날짜 CURRENT_DATE와 날짜이다 POST_DATE를 비교하고, 그것이 어떤 결과를 제공하지 않을 것이다.

당신이 현재 날짜와 비교하기 전에 만 현재까지 POST_DATE 변환합니다 다음과 같은 SQL을

$sql = 'SELECT * FROM wp_posts WHERE post_status = "publish" AND DATE(post_date) = CURRENT_DATE ORDER BY post_date DESC LIMIT 15'; 

을 시도 할 수 있습니다.

+0

고맙습니다. .. – Meo

관련 문제