我正在主页上显示最近发布的帖子,这些帖子正在WordPress网站上显示。现在,我必须在引导栏中显示记录,如下图所示。
图片说明:
1)前四行将显示第12行。
2)然后我必须将第8列和第4列分开。
3)在第8列中,我必须在第6-6列中显示我的记录的重置。
4)在第4列中,我必须显示一些不是来自数据库的静态文本。
所以我的HTML代码将显示如下。
<div class="container">
<div class="row">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12"></div>
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12"></div>
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12"></div>
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12"></div>
<div class="row">
<div class="col-xl-8 col-lg-8 col-md-8 col-sm-12 col-xs-12">
<div class="row">
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-xs-12"></div>
<div class="col-xl-6 col-lg-6 col-md-8 col-sm-12 col-xs-12"></div>
<!-- and so on -->
</div>
</div>
<div class="col-xl-4 col-lg-4 col-md-4 col-sm-12 col-xs-12">
<!-- html text this is not apart of for each-->
</div>
</div>
</div>
</div>
我的预期输出是
我对如何执行此操作感到困惑。目前,我正在第12列中获取所有记录。下面是我的代码。
function recentPost_on_home2(){
ob_start();
?>
<div class="cp-seeWrapper">
<div class="row">
<?php
global $paged;
$paged = $paged ? $paged : get_query_var( 'page' );
$args = array('posts_per_page' => 6,'paged'=> $paged,);
$tyler_query = new WP_Query( $args );
if ($tyler_query->have_posts()) {
while ( $tyler_query->have_posts() ) {
$tyler_query->the_post();
$names = array();
$categories = get_the_category();
foreach ( $categories as $i => $term ) {
if ( $i < 1 ) { // show at most two
$names[] = '<a href="' . esc_url( get_category_link( $term->term_id ) ) . '">' . $term->name . '</a>';
}
}
$names = implode( '',$names );
?>
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="cp-shadow cp-seeSinglePostWrapper">
<a href="<?php echo esc_url( get_the_permalink() );?>" title="<?php echo esc_attr( the_title_attribute('echo=0'));?>" class=""><?php echo get_the_post_thumbnail();?></a>
<div class="bg-white single-post-box">
<div class="d-flex cp-CategoryList">
<div class="seeDate"><?php echo get_the_date('F j,Y');?></div>
<div class="cp_cat_list"><?php echo $names;?></div>
</div>
<div class="cp-b-content">
<h2><a href="<?php echo esc_url( get_the_permalink() );?>" title="<?php echo esc_attr( the_title_attribute('echo=0'));?>" class=""><?php echo wp_trim_words(get_the_title(),12,'...');?></a>
</h2>
</div>
<p><?php echo wp_trim_words(get_the_excerpt(),25,'...');?></p>
</div>
</div>
</div>
<?php }?>
<?php }?>
<div class="col-xl-4 col-lg-4 col-md-4 col-sm-12 col-xs-12">
<div class="cp-social cp-shadow bg-white">
<h3>Social</h3>
</div>
</div>
<div class="cp-postPagination">
<div class="nav-previous cp-pagi float-left"><?php previous_posts_link(); ?></div>
<div class="nav-next cp-pagi float-right"><?php next_posts_link( null,$tyler_query->max_num_pages ); ?> </div>
<div class="clearfix"></div>
</div>
</div>
</div>
<?php return ob_get_clean();
}
add_shortcode( 'home_recent_post2','recentPost_on_home2' );