【问题标题】:How to show first post content and links for older post only in WordPress如何仅在 WordPress 中显示旧帖子的第一篇帖子内容和链接
【发布时间】:2014-03-26 10:03:13
【问题描述】:

我正在尝试创建报纸网站,需要帮助来显示最近帖子的内容和旧帖子的标题...这是我的代码

<?php
   $args = array(
                'orderby' => 'id',
                'hide_empty' => 1,
                'order' => 'ASC'
            );
    $categories = get_categories($args);
    foreach($categories as $category) { ?>
        <div class="newsdiv">
            <?php
                echo '<center><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></center> <br/> ';
                $post_args = array(
                         'numberposts' => 3,
                         'category' => $category->term_id 
                        );

                $posts = get_posts($post_args);

                foreach($posts as $post) {?>
                    <a href="<?php the_permalink(); ?>"><?php echo"*";the_title(); ?></a>
                    <div class="entry">
                        <?php the_content(); ?>
                    </div>
                <?php 
                } 
                echo '<dd class="view-all"> <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>Read more </a></dd>';
                echo '</dl>';
            ?>
        </div>
<?php   
    } 
?>

【问题讨论】:

  • 问题是……?

标签: php wordpress


【解决方案1】:

你可以试试codex以前的帖子

<?php previous_post_link( $format, $link, $in_same_cat = false, $excluded_terms = '', $taxonomy = 'category' ); ?> 

您可以像这样以更简单和/或复杂的方式使用它。

<?php previous_post_link(); ?> 

有关更多信息,您可以通过 codex http://codex.wordpress.org/Function_Reference/previous_post_link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-21
    • 1970-01-01
    • 2020-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-06
    相关资源
    最近更新 更多