如何构建html创世循环(Wordpress)?

如何构建html创世循环(Wordpress)?

问题描述:

I want edit default archive template. I created archive.php and add this code:

    function mpp_body_class( $classes ) {

    $classes[] = 'mpp-home';
    return $classes;

}
add_filter( 'body_class', 'mpp_body_class' );

// Force content-sidebar layout setting
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );


genesis();

How to call post loop and makeup html for it?

我想编辑默认存档模板。 我创建了archive.php并添加了这段代码: p>

  function mpp_body_class($ classes){
 
 $ classes [] ='mpp-home'; 
返回$ 类; 
 
} 
 
add_filter('body_class','mpp_body_class'); 
 
 //强制内容侧边栏布局设置
add_filter('genesis_pre_get_option_site_layout','__genesis_return_full_width_content'); 
 
 
ngenesis(  ); 
  code>  pre> 
 
 

如何为它调用post loop和makeup html? p> div>

You don't necessarily need to create a php file for customizing genesis,

you can simply build a custom loop directly on custom functions.php or any plugin

// hooking the modification on wp_head
add_action('wp_head', function() {

    // check if we are on archive pages, if not just return back
    if ( !is_archive() ) return; 

    //remove genesis default loop
    remove_action( 'genesis_loop', 'genesis_do_loop' );

    //add your custom loop
    add_action( 'genesis_loop', 'your_custom_loop_archive' );

    add_filter( 'body_class', 'mpp_body_class' );

    // Force content-sidebar layout setting
    add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );

});

function mpp_body_class( $classes ) {
    $classes[] = 'mpp-home';
    return $classes;
}

function your_custom_loop_archive() {

    // needed to get the queried date for date archive
    global $wp_query;

    // get current archive details, this return object user data for user 
    //returns NULL for date archive, that's why we have to also use $wp_query object for date
    $obj = get_queried_object();

    //build query paramter to get all the post of this archive
    $args = [
        'orderby' => 'menu_order', // overide default orderby
        'order' => 'ASC', // overide default orderb
        'posts_per_page'=> '12', // overrides default posts per 
    ];

    //add author paramater for author archive
    if ( is_author()  ) $args['author'] = $obj->ID;

    //add year & monthnum paramater for date archive 
    if ( is_date() ) $args = array_merge( $args, $wp_query->query  );

    //add tax_query paramater for taxonomy archive, includes categories & tags
    //is_tax() will return false for post category & tag 
    //we need to include is_category() and is_tag()
    // see https://core.trac.wordpress.org/ticket/18636
    if ( is_tax() || is_category() || is_tag() ) {
        $args['tax_query'] = [[
            'taxonomy' => $obj->taxonomy,
            'field' => 'id',
            'terms' => $obj->term_id,
        ]];
    }

    //build new query
    $loop = new WP_Query( $args );

    //duh Loop        
    if( $loop->have_posts() ):            
    while( $loop->have_posts() ): $loop->the_post(); global $post;

        // build your html template here
        echo '<pre>', print_r( $post, 1), '</pre>'; // spit each post object data

    endwhile;         
    endif;
}