【问题标题】:Custom blog page on Wordpress (PHP) - PaginationWordpress (PHP) 上的自定义博客页面 - 分页
【发布时间】:2012-09-18 04:45:38
【问题描述】:

我正在尝试在this page 上显示带有自定义缩略图和标题的前 5 个帖子,我只需要显示接下来 5 个帖子的标题,然后是分页。您可以查看我需要的示例by clicking here。 (见左边的帖子)

下面是我在页面上使用的自定义模板。

<?php
get_header(); ?>
<div id="primary">
<div id="content" role="main">

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts($args);
if( have_posts() ) :?>

<?php twentyeleven_content_nav( 'nav-above' );?>
<?php while ( have_posts() ) : the_post(); ?>
            <div class="post-thumb-title">
            <a href="<?php the_permalink() ?>"><?php the_post_thumbnail(array(632,305));?></a>
            <p class="thumb-title2"><?php the_title(); ?></p>
            <p class="news-date"><?php the_time('F jS, Y') ?></p>
            <div id="post-excerpt">
            <?php the_excerpt(); ?>
            </div>
            </div>
<?php endwhile; ?>
<?php twentyeleven_content_nav( 'nav-below' ); ?>

<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></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.', 'twentyeleven' ); ?></p>
<?php get_search_form(); ?>
</div>
<?php endif; ?>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

谢谢

【问题讨论】:

    标签: php html wordpress loops pagination


    【解决方案1】:

    你可以试试这样的

    <?php
    // amount of posts shown with thumbnail
    // post 6 .. pagesize (wp-admin > settings > reading) will be displayed as link only
    $withThumb = 5; 
    while ( have_posts() ) : the_post();
        if ($withThumb-- > 0) { ?>
            <div class="post-thumb-title">
                <a href="<?php the_permalink() ?>"><?php the_post_thumbnail(array(632,305));?></a>
                <p class="thumb-title2"><?php the_title(); ?></p>
                <p class="news-date"><?php the_time('F jS, Y') ?></p>
                <div id="post-excerpt">
                    <?php the_excerpt(); ?>
                </div>
            </div>
        <?php } else { ?>
            <div class="post-title">
                <p class="thumb-title2">
                    <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
                </p>
            </div>
        <?php } ?>
    <?php endwhile; ?>
    

    【讨论】:

    • 这打破了我的页面。没有运气。
    • 可能,没有测试,但收到任何错误消息/警告?
    • 不。只是一个空白页。我确定我正确地替换了我的代码,因为我检查了两次。
    • 有什么帮助吗? :(我被困在这个循环中
    • 经过测试,代码似乎没问题。可以肯定的是:只需替换&lt;?php twentyeleven_content_nav( 'nav-above' );?&gt;&lt;?php twentyeleven_content_nav( 'nav-below' ); ?&gt; 之间的部分。如果这仍然不起作用,您能否检查您的服务器错误日志并在页面刷新后发布添加到日志中的条目?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-08
    • 1970-01-01
    相关资源
    最近更新 更多