douhensheng1131 2015-06-15 22:06
浏览 69

想要在自定义页面中将分页添加到自定义帖子类型

I want to use a pagination to custom post in a custom pages.I have custom-posts.php page where i write the code

<?php 
function designs_theme_custom_post() {
    register_post_type( 'logo-portflio',
        array(
            'description' => 'logo-portflio Post Type',
            'show_ui' => true,
            'menu_position' => 4,
            'exclude_from_search' => true,      
            'labels' => array(
                'name' => __( 'logo-portflio Items' ),
                'singular_name' => __( 'portflio Item' ),
                'add_new' => __( 'Add New logo portflio Item' )
                        ),
            'public' => true,
            'supports' => array('title', 'editor', 'custom-fields', 'excerpt', 'thumbnail'),
            'has_archive' => true,
            'rewrite' => array('slug' => 'logo-portflio'),
            ));
        } 
add_action('init', 'designs_theme_custom_post');
?>

and call the post in logo-portfolio.php pages as

`<div class="portfolio">
    <ul class="items col4 border">
    <?php
        global $post;
        $args = array( 'posts_per_page' => 3, 'post_type'=> 'logo-portflio');
        $myposts = get_posts( $args );
        foreach( $myposts as $post ) : setup_postdata($post); ?>                    
    <?php
        $portfolio_large = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'portfolio-large' );
    ?>
    <!-- /.filter -->
<li class="item thumb">
   <figure class="icon-overlay icn-enlarge"><a href="<?php echo $portfolio_large[0]; ?>" class="fancybox-media" data-rel="portfolio"><?php the_post_thumbnail('portfolio-thumb'); ?> </a>
</figure>
    <div class="bordered no-top-border">
        <div class="info">
            <h3 class="post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <p><?php the_excerpt(); ?></p>
        </div>
     </div>
</li>
<!-- /.items --> 
    <?php endforeach; ?>
</ul>
</div>`

what i will do now to add add Pagination to custom post type in custom page.plase help me some one....

  • 写回答

1条回答 默认 最新

  • doushadu0901 2015-06-16 05:28
    关注

    Please try following code

    <?php 
     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
     $loop  = new WP_Query(
                array(
                    'post_type' => 'logo-portflio',
                    'post_status' => 'published',
                    'paged' => $paged,
                    'posts_per_page' => 3,
                    'orderby' => 'menuorder',
                    'caller_get_posts' => 1
                )
            );
    ?>  
    

    After that loop through post and add following:

     <?php 
       if ($loop->have_posts()) :
        while ( $loop->have_posts()) :  $loop->the_post(); 
    ?>
        <!-- Your post-displaying code here... -->
    
    <?php endwhile; ?>
    <?php 
            if(function_exists('wp_pagenavi')){ 
                wp_pagenavi(); 
            } 
    ?>
    <?php else : ?>
            <?php echo 'not post exits'; ?> 
    <?php endif; ?> 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题