programing

미디어 파일 워드프레스를 모두 받을 수 있는 기능은 무엇입니까?

lastcode 2023. 3. 23. 22:47
반응형

미디어 파일 워드프레스를 모두 받을 수 있는 기능은 무엇입니까?

워드프레스용 이미지를 모두 저장할 수 있는 기능이 무엇인지 제안해 주실 수 있습니까?Wordpress admin의 Media 메뉴에 표시되는 모든 이미지를 나열하기만 하면 됩니다.

잘 부탁드립니다

업로드된 이미지는 "attachment" 유형의 게시물로 저장됩니다. 올바른 매개 변수와 함께 get_posts()를 사용하십시오.get_posts()의 Codex 엔트리에서 다음 예를 나타냅니다.

<?php

$args = array(
    'post_type' => 'attachment',
    'numberposts' => -1,
    'post_status' => null,
    'post_parent' => null, // any parent
    ); 
$attachments = get_posts($args);
if ($attachments) {
    foreach ($attachments as $post) {
        setup_postdata($post);
        the_title();
        the_attachment_link($post->ID, false);
        the_excerpt();
    }
}

?>

...모든 첨부 파일을 검토하여 표시합니다.

TheDeadMedic의 코멘트대로, 이미지를 취득하고 싶은 경우는, 다음의 방법으로 필터링 할 수 있습니다.'post_mime_type' => 'image'의론에서.

<ul>
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post();    

                    $args = array(
                        'post_type' => 'attachment',
                        'numberposts' => -1,
                        'post_status' => null,
                        'post_parent' => $post->ID
                        );

                    $attachments = get_posts( $args );
                    if ( $attachments ) {
                        foreach ( $attachments as $attachment ) {
                            echo '<li>';
                            echo wp_get_attachment_image( $attachment->ID, 'full' );
                            echo '<p>';
                            echo apply_filters( 'the_title', $attachment->post_title );
                            echo '</p></li>';
                        }
                    }

            endwhile; endif; ?>
        </ul>

언급URL : https://stackoverflow.com/questions/3307576/what-is-the-function-got-get-all-the-media-files-wordpress

반응형