首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在我的自定义博客页面模板Wordpress上分页

在我的自定义博客页面模板Wordpress上分页
EN

Stack Overflow用户
提问于 2014-11-06 10:16:27
回答 1查看 2.7K关注 0票数 1

我已经创建了一个自定义的博客页面模板,但问题是我无法插入分页链接,但我想显示分页链接下一次和以前的博客底部,我应该做什么.

这是我的密码

代码语言:javascript
运行
复制
<?php /*
Template Name: My Blog Page
*/
?>

                <div class="col-md-9 col-sm-9">
                    <!-- Blog Post -->
                    <?php

                    $args = array('post_type' => 'post', 'posts_per_page' => 10,     'ignore_sticky_posts' => 1, 'category_name' => 'blog', );
                    $post_type_data = new WP_Query($args);
                    while ($post_type_data->have_posts()):
                        $post_type_data->the_post();
                        global $more;
                        $more = 0; ?>
                        <div class="row blog-row" style="padding: 20px 0;border- bottom: 1px solid #A9A9A9;">
                            <div style="width: 50%;float: left">
                            <div class="feature-image img-overlay">
                                <?php if (has_post_thumbnail()): ?>
                                    <?php $default = array('class' => 'img-responsive');
                                    the_post_thumbnail('wl_blog_img', $default); ?>
                                <?php endif; ?>
                            </div>
                            </div>
                            <div class="feature-content" style="padding-left: 15px;display: inline-block;width: 50%">
                                <h3 class="h3-blog-title">
                                    <a href="<?php echo the_permalink(); ?>"><?php echo the_title(); ?></a>
                                </h3>
                                <span style="padding-right: 5px"><i class="icon-picture"></i></span>
                                <span style="padding-right: 5px"><i class="icon-time"></i><?php echo get_the_date('j'); ?> <?php echo the_time('M'); ?>, <?php echo the_time('Y'); ?></span>
                                <span style="padding-right: 5px"><i class="icon-user"></i><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php echo get_the_author(); ?></a></span><br><br>

                                <?php the_excerpt(); ?>
                                <a class="my-btn" href="<?php echo the_permalink(); ?>">Read More</a>
                            </div>
                            <div class="feature-details1">
                            </div>
                        </div>
                    <?php endwhile; ?>
                    <!-- //Blog Post// -->
                </div>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-06 10:20:57

使用以下代码进行分页

代码语言:javascript
运行
复制
 <?php /*
    Template Name: My Blog Page
    */
 ?><div class="col-md-9 col-sm-9">
                    <!-- Blog Post -->
                    <?php
                    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                    $args = array('post_type' => 'post', 'posts_per_page' => 2,     'ignore_sticky_posts' => 1, 'category_name' => 'blog', 'paged' => $paged );

                    $post_type_data = new WP_Query($args);

                    set_query_var('page',$paged);
                    while ($post_type_data->have_posts()):
                    $post_type_data->the_post();
                    global $more;
                        $more = 0; ?>
                        <div class="row blog-row" style="padding: 20px 0;border- bottom: 1px solid #A9A9A9;">
                            <div style="width: 50%;float: left">
                            <div class="feature-image img-overlay">
                                <?php if (has_post_thumbnail()): ?>
                                    <?php $default = array('class' => 'img-responsive');
                                    the_post_thumbnail('wl_blog_img', $default); ?>
                                <?php endif; ?>
                            </div>
                            </div>
                            <div class="feature-content" style="padding-left: 15px;display: inline-block;width: 50%">
                                <h3 class="h3-blog-title">
                                    <a href="<?php echo the_permalink(); ?>"><?php echo the_title(); ?></a>
                                </h3>
                                <span style="padding-right: 5px"><i class="icon-picture"></i></span>
                                <span style="padding-right: 5px"><i class="icon-time"></i><?php echo get_the_date('j'); ?> <?php echo the_time('M'); ?>, <?php echo the_time('Y'); ?></span>
                                <span style="padding-right: 5px"><i class="icon-user"></i><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php echo get_the_author(); ?></a></span><br><br>

                                <?php the_excerpt(); ?>
                                <a class="my-btn" href="<?php echo the_permalink(); ?>">Read More</a>
                            </div>
                            <div class="feature-details1">
                            </div>
                        </div>
                    <?php endwhile; ?>
<div class="nav-previous alignleft"><?php previous_posts_link('&laquo; Newer posts');?></div>
                        <div class="nav-next alignright"><?php next_posts_link( 'Older posts &raquo;', $post_type_data->max_num_pages ); ?></div>
                    <!-- //Blog Post// -->
                </div>  
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26776844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档