Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress时间线添加标题季度1月至3月,依此类推_Php_Css_Wordpress - Fatal编程技术网

Php Wordpress时间线添加标题季度1月至3月,依此类推

Php Wordpress时间线添加标题季度1月至3月,依此类推,php,css,wordpress,Php,Css,Wordpress,我有没有办法在1月至3月的顶部显示在1月至3月的标题下?然后是四月到六月,七月到九月,十月到十二月。这是我的网页链接 这是我的时间线模板代码 <!-- Timeline begin here --> <div id="timeline"> <?php //Define your custom post type name in the arguments $args = array('post_type' => 'timeline', 'ord

我有没有办法在1月至3月的顶部显示在1月至3月的标题下?然后是四月到六月,七月到九月,十月到十二月。这是我的网页链接

这是我的时间线模板代码

<!-- Timeline begin here -->
<div id="timeline">
<?php
    //Define your custom post type name in the arguments
    $args = array('post_type' => 'timeline', 'order' => 'asc');
    //Define the loop based on arguments
    $loop = new WP_Query( $args );
    //Display the contents
    while ( $loop->have_posts() ) : $loop->the_post();
    $thumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID,'large') );
?>
<section id="<?php the_time( 'M' );?>">
    <div class="timeline-item">
        <?php
            if( $loop->current_post === 0 ) {
        ?>
        <div class="timeline-icon">
            <div class="timeline-month">
                <?php the_time( 'M' );?>
            </div>
        </div>
        <?php $current_month = get_the_time('M'); ?>
        <?php } else {
            $post_month = get_the_time('M');
            if($current_month != $post_month) {
        ?>
        <div class="timeline-icon">
            <div class="timeline-month">
                <?php the_time( 'M' );?>
            </div>
        </div>
        <?php }
            }
            $current_month = get_the_time('M');
        ?>
        <div class="timeline-content right">
            <h2>
                <?php the_title(); ?>
            </h2>
            <p>
                <?php echo the_content(); ?>
            </p>
            <div class="timeline_img">
                <img src="<?php echo $thumb; ?>" class="img-responsive">
            </div>
        </div>
    </div>
</section>
<?php endwhile;?>
</div>
</div><!-- Column End -->
</div><!-- Container End -->


我认为您最好的选择是通过使用为每个季度使用
WP\u Query
的实例

以下是一个例子:

<!-- Timeline begin here -->
<div id="timeline">
    <?php
    //Define your custom post type name in the arguments
    $args = array('post_type' => 'timeline', 'order' => 'asc');

    $current_year = get_the_time('Y');

    $quarters = array(
        // Q1, January - March
        __( 'January - March' ) => array(
            'after' => array(
                'year' => $current_year,
                'month' => 1,
                'day' => 1,
            ),
            'before' => array(
                'year' => $current_year,
                'month' => 3,
                'day' => 31,
            ),
            /* Set inclusive to true so we capture
            ** posts on the before/after days
             */
            'inclusive' => true,
        ),
        // Q2, April - June
        __( 'April - June' ) => array(
            'after' => array(
                'year' => $current_year,
                'month' => 4,
                'day' => 1,
            ),
            'before' => array(
                'year' => $current_year,
                'month' => 6,
                'day' => 30,
            ),
            'inclusive' => true,
        ),
        // Q3, July - September
        __( 'July - September' ) => array(
            'after' => array(
                'year' => $current_year,
                'month' => 7,
                'day' => 1,
            ),
            'before' => array(
                'year' => $current_year,
                'month' => 9,
                'day' => 30,
            ),
            'inclusive' => true,
        ),
        // Q4, October - December
        __( 'October - December' ) => array(
            'after' => array(
                'year' => $current_year,
                'month' => 10,
                'day' => 1,
            ),
            'before' => array(
                'year' => $current_year,
                'month' => 12,
                'day' => 31,
            ),
            'inclusive' => true,
        ),
    );

    foreach ( $quarters as $quarter_heading => $quarter_date_query ):

        // set current quarter args to our default args
        $quarter_args = $args;

        // add the date query for this quarter
        $quarter_args['date_query'] = $quarter_date_query;

        // display the heading for the current quarter
        ?>

        <div class="quarterlyheading">
            <?php echo  $quarter_heading; ?>
            <div class="quarterlinebreak"><hr></div>
        </div>

        <?php    
        // loop through the posts for the current quarter

        //Define the loop based on arguments
        $loop = new WP_Query( $quarter_args );

        //Display the contents
        while ( $loop->have_posts() ) : $loop->the_post();
            $thumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID,'large') );
            ?>
            <section id="<?php the_time( 'M' );?>">
                <div class="timeline-item">
                    <?php
                    if( $loop->current_post === 0 ) {
                        ?>
                        <div class="timeline-icon">
                            <div class="timeline-month">
                                <?php the_time( 'M' );?>
                            </div>
                        </div>
                        <?php $current_month = get_the_time('M'); ?>
                    <?php } else {
                        $post_month = get_the_time('M');
                        if($current_month != $post_month) {
                            ?>
                            <div class="timeline-icon">
                                <div class="timeline-month">
                                    <?php the_time( 'M' );?>
                                </div>
                            </div>
                        <?php }
                    }
                    $current_month = get_the_time('M');
                    ?>
                    <div class="timeline-content right">
                        <h2>
                            <?php the_title(); ?>
                        </h2>
                        <p>
                            <?php echo the_content(); ?>
                        </p>
                        <div class="timeline_img">
                            <img src="<?php echo $thumb; ?>" class="img-responsive">
                        </div>
                    </div>
                </div>
            </section>
        <?php
        endwhile;

        // reset post data
        wp_reset_postdata();

    endforeach;

?>
</div>



提示:你只需要调整你的if-else结构来检查一系列的月份,而不是简单地检查一个特定的月份。你知道我如何检查吗?没问题!如果这解决了您的问题,请将答案标记为已接受。如果你仍然有问题的帖子和更新,我会再看一遍。