簡體   English   中英

WP從每個類別獲取具有自定義帖子格式的帖子

[英]WP get posts with custom post format from every category

我正在嘗試獲取所有類別的帖子,但要使用一種帖子格式,即名為homePost的帖子格式,我只是WordPress的初學者,我剛剛完成了前端開發和PHP + MySQL開發的學習,我需要您的幫助: )

這是我的代碼

<?php $args = array( 'orderby' => 'name', 'parent' => 0 );
$categories = get_categories( $args );
foreach ( $categories as $category ) {

$homePosts = array(
'post_type'=> 'post',
'post_status' => 'publish',
'category'         => $category->cat_ID,
'order' => 'DESC',
'tax_query' => array(
     array(
    'taxonomy' => 'post_format',
    'field' => 'slug',
    'terms' => array( 'homePost' )
    )
    )
);

    $asides = get_posts( $homePosts );
    if ( count($asides) ) {
        foreach ( $asides as $homePosts ) {
            '<p>' + 'Test' + '</p>' ;
        }
    }

}
?>

嗨,以相同的主題創建一個PHP文件,並在其中命名您的名字

<?php
        /*
        Template Name: Contact Us
        */
?>

在右側的管理面板頁面中,就像模板一樣,從下拉列表中選擇模板名稱

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM