如何显示每月的档案帖子?

时间:2014-06-27 作者:Riffaz Starr

我的自定义存档页是:

<?php get_header(); 

print (\'<div class="row">\');
    $archi = wp_get_archives(\'echo=0\');
    $archi = explode( \'</li>\' , $archi );
    $archi_count = count($archi);
    $count = 1;
    $itemCount = 0;
    foreach( $archi as $link ) {
        $link = str_replace( array( \'<li>\' , "\\n" , "\\t" , "\\s" ), \'\' , $link );
        if($count == 1) {
            print(\'<div class="medium-4 large-4 columns category_list"><ul>\');
                $itemCount++;
        }
        if(!empty($link)){  
            $arr = array($link);
            print(\'<li>\' . $arr[\'0\'] . \'</li> \');
            $itemCount++;
        }
        else continue;          
        if($count == (ceil($archi_count/3))) {
            print(\'</ul></div>\');
            $count=1;
        }
        else $count++;  
    }
    if ($count != (ceil($archi_count/3)) && $count > 1) // If last column does not have it\'s 7 items, then close the column
        print(\'</ul></div>\');
print(\'</div>\');

get_footer(); ?>
它显示了几个月的归档链接列表,如2014年4月。当我单击时,它会重定向到htttp://www.mysite.com/blog/2014/04.在这个页面中,我如何显示2014年4月发布的所有帖子。?中的平均值date.php..

我的约会对象。php

<?php
$args = array( ****WHAT ARE THE ARGUMENTS I HAVE TO PASS HERE?****);        
$lastposts = get_posts( $args );
foreach($lastposts as $post) : setup_postdata($post);
archive_row();
endforeach; ?>
在功能中。php

function archive_row() { // archive rows archive.php, date.php
    echo \'<div class="large-3 medium-3 columns"><a href="\' . get_permalink() .\'" title="\' . get_the_title() . \'"><img src="\' .archive_thumb() .\'" alt="Banner Image x 4" style="width:100%" /></a><a href="\' .get_permalink() . \'" title="\' . get_the_title() . \'">\' . get_the_title() .\'</a></div>\';        
    }

2 个回复
SO网友:TBI Infotech

创建文件日期。在您的活动主题中使用php并使用以下代码,您可能需要根据您的要求完善此代码:

<div id="content" class="post-archive<?php echo $content_class; ?>">
    <?php if ( have_posts() ) : ?>

        <header class="archive-header">
            <h3 class="archive-title">

                <?php if ( is_day() ) : ?>
                    <?php printf( __( \'Daily Archives: %s\' ), \'<span>\' . get_the_date() . \'</span>\' ); ?>
                <?php elseif ( is_month() ) : ?>
                    <?php printf( __( \'Monthly Archives: %s\' ), \'<span>\' . get_the_date( _x( \'F Y\', \'monthly archives date format\', \'fairpixels\' ) ) . \'</span>\' ); ?>
                <?php elseif ( is_year() ) : ?>
                    <?php printf( __( \'Yearly Archives: %s\' ), \'<span>\' . get_the_date( _x( \'Y\', \'yearly archives date format\', \'fairpixels\' ) ) . \'</span>\' ); ?>
                <?php else : ?>
                    <?php _e( \'Blog Archives\' ); ?>
                <?php endif; ?>
            </h3>
        </header>

        <div class="archive-postlist">
            <?php $i = 0; ?>                
            <?php while ( have_posts() ) : the_post(); ?>
                <?php                               
                    $post_class ="";
                    if ( $i % 2 == 1 ){
                        $post_class =" col-last";
                    }                   
                ?>  
                <div class="one-half<?php echo $post_class; ?>">
                    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>   

                                                    <?php       
                                                             if ( has_post_thumbnail() ) {  ?>

                                                                    <div class="thumb overlay">
                                                                            <a href="<?php the_permalink() ?>"><?php the_post_thumbnail( ); ?></a>
                                                                    </div>  
                                                    <?php } ?>

                                                    <header class="entry-header">
                                                            <h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4>
                                                            <div class="entry-meta">
                                                                    <span class="date">
                                                                            <?php echo get_the_date(); ?>
                                                                    </span>


                                                            </div>
                                                    </header>

                                                    <div class="entry-excerpt">
                                                            <?php the_excerpt(); ?>
                                                    </div>

                                            </article>
                </div>
                <?php $i++; ?>
            <?php endwhile; ?>
        </div>
        <?php //fp_pagination(); ?>         
    <?php else : ?>

        <article id="post-0" class="post no-results not-found">
            <header class="entry-header">
                <h1 class="entry-title"><?php _e( \'Nothing Found\'); ?></h1>
            </header><!-- /entry-header -->

            <div class="entry-content">
                <p><?php _e( \'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.\', \'fairpixels\' ); ?></p>
                <?php get_search_form(); ?>
            </div><!-- /entry-content -->
        </article><!-- /post-0 -->

    <?php endif; ?>
</div><!-- /content -->

SO网友:Hendrik Luehrsen

这里值得注意的是Wordpress的模板层次结构。(http://codex.wordpress.org/Template_Hierarchy)

这些模板基本上覆盖了所有Wordpress页面所需的99%。如果您在这样一个模板的领域内工作,就不需要生成自己的查询,Wordpress已经这样做了,您所要做的就是生成一个循环来显示结果。

这是一个相当标准的存档。我用来在博客上显示归档文件的php。

<?php
    get_header();

    $post = $posts[0]; // Hack. Set $post so that the_date() works. 
    /* If this is a category archive */ if (is_category()) { 
        $title =__(single_cat_title(\'\', false)); 
    /* If this is a tag archive */ } elseif( is_tag() ) { 
        $title =__(\'Tag: \', "krautgaming")." ".single_tag_title(\'\', false); 
    /* If this is a daily archive */ } elseif (is_day()) { 
        $title =__(\'Archive for \', "krautgaming").get_the_time(__(\'F jS, Y\', "krautgaming")).__(\' | Daily archive page\', "krautgaming"); 
    /* If this is a monthly archive */ } elseif (is_month()) { 
        $title =__(\'Archive for \', "krautgaming").get_the_time(__(\'F, Y\', "krautgaming")).__(\' | Monthly archive page\', "krautgaming"); 
    /* If this is a yearly archive */ } elseif (is_year()) { 
        $title =__(\'Archive for \', "krautgaming").get_the_time(__(\'Y\', "krautgaming")).__(\' | Yearly archive page\', "krautgaming"); 
    /* If this is an author archive */ } elseif (is_author()) { 
        $title =__(\'Author Archive\', "krautgaming"); 
    /* If this is a paged archive */ } elseif (isset($_GET[\'paged\']) && !empty($_GET[\'paged\'])) { 
        $title =__(\'Blog Archives\', "krautgaming"); 
    /* If this is a channel archive */ } elseif (is_tax(\'channel\')) {
        $title =__(\'Videos by\', "krautgaming")." ".single_tag_title(\'\', false);
    /* If this is a video archive */ } elseif (is_post_type_archive(\'video\')) {
        $title =__(\'Recent Videos\', "krautgaming");
    } else {
        $title =__("Recent Posts", "krautgaming");
    }
?>

<div class="sub_header">
    <div class="container">
        <div class="row">
            <div class="span6">
                <h1><?php echo $title; ?></h1>
            </div>
        </div>
    </div>
</div>

<div class="center-container container">
    <?php
        if( have_posts() ): while( have_posts() ): the_post();
    ?>
        <!-- Display posts here -->
    <?php
        endwhile; endif;
    ?>
</div>

<?php
    get_footer();
?>

结束

相关推荐

List all blog categories

我已经创建了一个博客插件。我的博客中有博客类别。我想获得所有博客类别的列表,并将其列在我的www.domain中。com/blogs/page。我的博客类别名称为“blogcategory”。我不知道如何在list-category 作用我是wordpress开发的nooby。