Php 手动编号分页是';t在wordpress模板文件中工作

Php 手动编号分页是';t在wordpress模板文件中工作,php,wordpress,pagination,Php,Wordpress,Pagination,我有这段代码,显示“旧条目”和“新条目”。但是,我想编辑此代码以显示“1”、“2”、“3”等,而不显示左/右箭头或Prev/Nex文本。因此,我做了研究,感到困惑。我可以理解教程中的内容,比如(底部是编号分页),但是他们没有说明代码应该放在哪里。只有第二个教程完整地解释了我需要做什么,但即使如此,这种方式也不起作用 我的工作代码: $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; // the query

我有这段代码,显示“旧条目”和“新条目”。但是,我想编辑此代码以显示“1”、“2”、“3”等,而不显示左/右箭头或Prev/Nex文本。因此,我做了研究,感到困惑。我可以理解教程中的内容,比如(底部是编号分页),但是他们没有说明代码应该放在哪里。只有第二个教程完整地解释了我需要做什么,但即使如此,这种方式也不起作用

我的工作代码:

$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

// the query
$the_query = new WP_Query( 'cat=9&posts_per_page=9&paged=' . $paged ); 
?>

<?php if ( $the_query->have_posts() ) : ?>

<?php
// the loop
while ( $the_query->have_posts() ) : $the_query->the_post(); 
?>

<div class="proyectpost">
            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

            <div class="innerpost">

             <div class="postthumbnail">
            <?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
    $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' );
     echo '<img src="' . $image_src[0]  . '" width="100%"  />';
    } ?>
            </div>
            <div class="posttitle">
        <h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
            </div><!-- .entry-header -->

        <div class="postsubtitle">
        <div class="datepanel">

        </div>
        </div>

</div>
</article><!-- #post-## --> 

</div>


<?php endwhile; ?>

<?php

// next_posts_link() usage with max_num_pages
next_posts_link( 'Older Entries', $the_query->max_num_pages );
previous_posts_link( 'Newer Entries' );
?>

<?php 
// clean up after the query and pagination
wp_reset_postdata(); 
?>

<?php else:  ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
并用此代码替换默认分页

<?php wpex_pagination(); ?>


如何在我的wordpress模板php文件中显示带编号的分页?

在进一步研究之后,我发现了一些线索,这些线索启发我找到了将正确代码放置在何处的方法,以便获得带编号的分页

您可以使用以下代码:

<?php
$big = 999999999; // need an unlikely integer

echo paginate_links( array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, get_query_var('paged') ),
    'total' => $the_query->max_num_pages
) );
?>

取代:

<?php

// next_posts_link() usage with max_num_pages
next_posts_link( 'Older Entries', $the_query->max_num_pages );
previous_posts_link( 'Newer Entries' );
?>

我想让我困惑的是,当我在研究的时候,一些人说在functions.php中添加一些代码,而另一些人说在某些地方使用其他代码。因此,当我阅读时,这个页面不清楚是否应该将上面的新代码添加到functions.php或替换“prev/next”链接


不管怎样,它现在起作用了!:)

您只需要使用教程的最后一部分更新主题模板文件-即使它还不存在,也需要有
来输出分页。我应该将它放在哪里?我使用此“”替换“”,但它没有显示任何结果。根据您的问题,应该会输出分页。请确保您在正确的模板文件上执行此操作。我使用的模板是template-proyectos.php。这是一个模板页面。单个页面不会分页,您必须在存档或分类页面上使用它。
<?php

// next_posts_link() usage with max_num_pages
next_posts_link( 'Older Entries', $the_query->max_num_pages );
previous_posts_link( 'Newer Entries' );
?>