programing

Wordpress에서 게시 날짜를 포맷하려면 어떻게 해야 합니까?

muds 2023. 3. 7. 22:10
반응형

Wordpress에서 게시 날짜를 포맷하려면 어떻게 해야 합니까?

최근 게시물을 표시하는 사이드바가 있습니다.제목, 날짜 및 발췌가 표시됩니다.날짜는 내가 없애고 싶은 시간을 보여준다.날짜를 표시하려면 $reent["post_date"]

 <?php
$args = array( 'numberposts' => '3' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
    echo '<li id="sidebar_text"><b>'.$recent["post_title"].'</b></li><li style="font-size:12px">'.$recent["post_date"].'</li><li><i style="font-size:15px">'.$recent["post_excerpt"].'</i><a href="'.get_permalink($recent["ID"]).'"> Read   More</a></li>';
     }
 ?>

2013년 8월 8일 18:29:04와 같은 날짜로 되어 있으며, 시간이 없는 2013년 8월 11일 8:29:04로 부탁드립니다.잘 부탁드립니다.

date('n-j-Y', strtotime($recent['post_date']));

원하는 대로 포맷할 수 있습니다.를 교환해 주세요.$recent['post_date']네 루프에 넣어줘.

Syfaro의 답변은 맞지만, 이를 위해 WordPress의 자체 기능을 사용하는 것이 좋습니다.

get_the_date

기본적으로는 WordPress 관리 설정(설정 -> 일반)에서 설정된 형식이므로 향후 편집 시 보다 접근하기 쉬운 솔루션이 제공됩니다.여러 사이트에서 코드를 롤하는 경우나 공개하는 경우 특히 유용합니다.

또한 출력 이스케이프도 잊지 마십시오.esc_htmlesc_html_e를 확인하십시오.

date_i18n('l d/m/Y \à\s g:i', strtotime($item['time']))

교체하다$recent["post_date"]와 함께mysql2date('n-j-Y', $recent['post_date']).

언급URL : https://stackoverflow.com/questions/18175498/how-do-i-format-the-post-date-in-wordpress

반응형