实施的WP-PageNavi对我的自定义帖子类型不起作用

时间:2019-02-06 09:15:35

标签: php wordpress pagination

我实现了“自定义帖子类型”,因此需要在更多页面上对所有帖子进行分页。我安装了wp-pagenavi,但是当我尝试选择第2页时,URL更改了,但是内容将保留在第1页上,并且没有任何更改。

自定义帖子类型是在管理模式下创建的,而不是通过=> register_post_type()

创建的

我在代码中实现了错误吗?

 <?php
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        $args = array('post_type' => 'inzeraty',
            'order' => 'ASC',
            'posts_per_page' => 2,
            'paged' => $paged);
        $wp_query = new WP_Query( $args );

            while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
                <div class="col-12">
                    <div class="cpt-news-block mb-3">
                        <div class="row">
                            <div class="col-12 col-sm-6 col-lg-12 col-xl-6">
                                <a class="zoom-picture-hover" href="<?php the_permalink()?>">
                                    <div class="cpt-news-block-image picture">

                <?php $images = acf_photo_gallery('fotka', $post->ID);

                $image = $images[0];
                $id = $image['id']; // The attachment id of the media
                $title = $image['title']; //The title
                $caption= $image['caption']; //The caption
                $full_image_url= $image['full_image_url']; //Full size image url
                //$full_image_url = acf_photo_gallery_resize_image($full_image_url, 762, 580); //Resized size to 262px width by 160px height image url
                $thumbnail_image_url= $image['thumbnail_image_url']; //Get the thumbnail size image url 150px by 150px
                $url= $image['url']; //Goto any link when clicked
                $target= $image['target']; //Open normal or new tab
                $alt = get_field('photo_gallery_alt', $id); //Get the alt which is a extra field (See below how to add extra fields)
                $class = get_field('photo_gallery_class', $id); //Get the class which is a extra field (See below how to add extra fields)
                ?>

                <?php if( !empty($url) ){ ?><a href="<?php echo $url; ?>" <?php echo ($target == 'true' )? 'target="_blank"': ''; ?>><?php } ?>
                <img src="<?php echo $full_image_url; ?>" alt="<?php echo $title; ?>" title="<?php echo $title; ?>">
                <?php if( !empty($url) ){ ?></a><?php } ?>

                                    </div>
                                </a>
                            </div>
                            <div class="col-12 col-sm-6 col-lg-12 col-xl-6">
                                <h2 style="font-size: 20px;">
                                    <a href="<?php the_permalink()?>">
                                        <?php the_title()?>
                                    </a>
                                </h2>
                                <p class="mb-3"><?php the_field('popis_inzeratu')?></p>
                                <a href="<?php the_permalink()?>" class="cpt-news-block-link link-read-more"> <?php
                                    include get_stylesheet_directory() . '/assets/img/svg/icon_arrow.svg';
                                    ?>
                                   <?php echo "More";?>
                                </a>
                            </div>
                        </div>

                    </div>
                </div>
            <?php endwhile;?>
        <?php wp_pagenavi( array( 'query' => $wp_query ) ); ?>

我页面的网址:http://tvorba-stranok.eu/ads/

感谢您的任何建议...

1 个答案:

答案 0 :(得分:0)

  

安装插件“自定义帖子类型” UI以轻松添加自定义帖子   类型。您必须更改此插件的设置才能使用。   当您将Rewrite设置为false(针对您的自定义帖子类型)时,它将   工作。清除永久链接设置。

尝试以下代码。我已使用最少的信息进行检查。

 <?php
// Must have wp_pagenavi plugin installed. Custom Post Type names can not clash with page names or 404's will occur on /page/#/ (Utilize Custom Rewrite Slug in CPT)
            // The press release loop
            $the_inzeraty = new WP_Query(array('post_type' => 'inzeraty','posts_per_page' => 10,'paged'=> get_query_var('paged') ));
            // The Loop
            while ($the_inzeraty->have_posts()) : $the_inzeraty->the_post();
                ?>
                <h2><?php the_title(); ?></h2>
                <p><?php the_excerpt(); ?></p>
                <p><a href="<?php echo the_permalink(); ?>" >Read More</a></p>
            <?php endwhile; ?>
            <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(array('query'=> $the_inzeraty));} ?>
<?php wp_reset_postdata();?>