Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 自定义分类分页404(附件)_Php_Wordpress_Pagination - Fatal编程技术网

Php 自定义分类分页404(附件)

Php 自定义分类分页404(附件),php,wordpress,pagination,Php,Wordpress,Pagination,我为媒体区域创建了一个分类法,因此我可以将我的所有图像分配到特定的类别。我的分类页面一切正常,直到我尝试转到第2页,在这一点上,它抛出一个404 在过去的几天里,我已经尝试了大约8000种不同的重写规则函数。我已经更新了大约9000次permalinks。但当我点击第二页的链接时,它仍然给我一个404 以下是我的分类功能: add_action( 'init', 'create_media_hierarchical_taxonomy', 0 ); function create

我为媒体区域创建了一个分类法,因此我可以将我的所有图像分配到特定的类别。我的分类页面一切正常,直到我尝试转到第2页,在这一点上,它抛出一个404

在过去的几天里,我已经尝试了大约8000种不同的重写规则函数。我已经更新了大约9000次permalinks。但当我点击第二页的链接时,它仍然给我一个404

以下是我的分类功能:

    add_action( 'init', 'create_media_hierarchical_taxonomy', 0 );

    function create_media_hierarchical_taxonomy() {

      $labels = array(
        'name' => _x( 'Media Categories', 'taxonomy general name' ),
        'singular_name' => _x( 'Media Category', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Media Categories' ),
        'all_items' => __( 'All Media Categories' ),
        'parent_item' => __( 'Parent Media Category' ),
        'parent_item_colon' => __( 'Parent Media Category:' ),
        'edit_item' => __( 'Edit Media Category' ), 
        'update_item' => __( 'Update Media Category' ),
        'add_new_item' => __( 'Add New Media Category' ),
        'new_item_name' => __( 'New Media Category' ),
        'menu_name' => __( 'Media Categories' ),
      );    

      register_taxonomy('mediacat','attachment', array(
        'hierarchical' => true,
        'exclude_from_search' => false,
        'labels' => $labels,
        'show_ui' => true,
        'show_admin_column' => true,
        'query_var' => true,
        'public' => true,
        'publicly_queryable' => true,
        'capability_type' => 'attachment',
        'has_archive' => true,
        'rewrite' => array( 'slug' => 'imagetags' ),
        'update_count_callback' => '_update_post_cat_count',
        'show_in_rest' => true
      ));
    }
这是我的整个分类mediacat php文件

    get_header();

            <div id="post-<?php the_ID(); ?>" <?php post_class(''); ?>>
                <div class="content container-fluid" style="padding: 0 !important;">
                    <div class="row justify-content-center">
                        <div class="col-md-9">
                            <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

                            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                            $current_term_id = $term->term_id;
                            $current_name = $term->name;
                            $current_taxonomy = $term->taxonomy;
                            $current_parent = $term->parent;

                            echo '<strong>'.$current_name.'</strong>';

                            $sub_terms = get_terms( array(
                                'taxonomy' => $current_taxonomy,
                                'child_of' => $current_term_id,
                                'hide_empty' => false,
                            ) );

                            if ($sub_terms) {
                            ?>
                            <ul class="sub-terms">
                                <?php foreach ($sub_terms as $sub_term) { ?>
                                <li><a href="<?php echo get_term_link( $sub_term ) ?>"><?php echo $sub_term->name?></a></li>
                                <?php }// END foreach ?>
                            </ul><!-- END .sub-terms -->
                            <?php }// END if ?>

                            <main>
                                <div class="container-fluid">
                                    <div class="row justify-content-center">
                                        <div class="pagination_links" style="clear: both;">
                                            <?php $args = array(
                                                    'post_type' => 'attachment',
                                                    'post_mime_type' => 'image',
                                                    'tax_query'       => array(
                                                        array(
                                                            'taxonomy' => $term->taxonomy,
                                                            'field' => 'term_id',
                                                            'terms' => $term_id
                                                        )
                                                    )
                                                    'orderby' => 'title',
                                                    'order' => 'asc',
                                                    'posts_per_page' => '20',
                                                    'paged' => $paged,
                                                    'post_status' => 'inherit'
                                                );

                                                $loop = new WP_Query( $args );

                                            ?>
                                            Page: <?php $big = 999999999; // need an unlikely integer
                                                $translated = __( 'Page', 'ansel' ); // Supply translatable string

                                                echo paginate_links( array(
                                                    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                                                    'format' => '?paged=%#%',
                                                    'current' => max( 1, get_query_var('paged') ),
                                                    'total' => $loop->max_num_pages,
                                                    'before_page_number' => '<span class="screen-reader-text">'.$translated.' </span>'
                                                ) );
                                            ?>
                                        </div>
                                    </div>

                                    <div class="row justify-content-center">
                                        <form class="wpsp-page-nav-form" action="<?php echo $_SERVER['REQUEST_URI'];?>" method="get" style="text-align: center;">
                                            <label for="sortby" class="wpsp-label wpsp-hidden"><?php _e('Jump to', 'wp-smart-pagination'); ?></label>
                                            <div class="input-append" style="display: inline-block;">
                                                <input class="wpsp-input-number" type="text" placeholder="page..."  size="15" name="paged" />
                                                <button class="btn" type="submit"><i class="fa fa-arrow-right" aria-hidden="true"></i></button>
                                            </div>
                                        </form>
                                    </div>

                                    <div class="row justify-content-center">
                                        <div class="container-fluid">

                                            <div class="grid">
                                                <div class="grid-sizer"></div>
                                                <?php if ( $loop->have_posts() ) {
                                                    while ( $loop->have_posts() ) {
                                                        $loop->the_post();

                                                        $i = 0;
                                                        $item = get_the_id();
                                                        $atts = wp_get_attachment_image_src($item, 'full');
                                                        $image_all = wp_prepare_attachment_for_js($item);
                                                        $attachment_page = wp_get_attachment_url( $item );
                                                        $title = wp_prepare_attachment_for_js($item);
                                                        $image_title = wp_prepare_attachment_for_js($item);
                                                ?>

                                                <div class="grid-item">
                                                    <img src="<?php echo $atts[0]; ?>" alt="<?php echo $image_all['alt']; ?>">
                                                    <h3 class="entry-title"><?php echo $image_title['title']; ?></h3>
                                                    <p>keywords: <em><?php if (empty($image_all['alt'])) { echo $image_all['caption']; } else { echo $image_all['alt']; } ?></em></p>
                                                    <div id="fileName<?php echo $i; ?>" style="display: none;"><?php echo $image_title['title']; ?></div>
                                                    <div class="btn-group">
                                                        <button class="btn btn-primary btn2 js-tooltip" id="btnCopy" rel="fileName<?php echo $i; ?>" type="button" data-toggle="popover" title="copied">Copy Filename</button>
                                                        <button type="button" class="btn btn-default btn2 js-tooltip" id="btnCopy" rel="fileName" type="button" data-toggle="popover" title="copied">
                                                            <!-- icon from google's material design library -->
                                                            <svg class="icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24">
                                                                <path d="M17,9H7V7H17M17,13H7V11H17M14,17H7V15H14M12,3A1,1 0 0,1 13,4A1,1 0 0,1 12,5A1,1 0 0,1 11,4A1,1 0 0,1 12,3M19,3H14.82C14.4,1.84 13.3,1 12,1C10.7,1 9.6,1.84 9.18,3H5A2,2 0 0,0 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5A2,2 0 0,0 19,3Z" />
                                                            </svg>
                                                        </button>
                                                    </div>
                                                    <button id="btn_link" class="btn btn-secondary btn-lg" type="button">
                                                        <a href="#" data-toggle="modal" data-target="#galleryModal<?php echo $i; ?>" data-backdrop="static" data-keyboard="false">Suggest keywords for this item</a>
                                                    </button>
                                                </div>

                                                <!-- Modal -->
                                                <div class="modal fade" id="galleryModal<?php echo $i; ?>" tabindex="-1" role="dialog" aria-labelledby="galleryModalLabel<?php echo $i; ?>" aria-hidden="true">
                                                    <div class="modal-dialog modal-lg modal-dialog-centered">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                            </div>
                                                            <div class="modal-body d-flex h-100">
                                                                <div class="row justify-content-center align-self-center">
                                                                    <div class="col-md-6" style="text-align: center;">
                                                                        <img src="<?php echo $atts[0]; ?>" class="img-fluid img-thumbnail">
                                                                    </div>
                                                                    <div class="col-md-6">
                                                                        <div class="row">
                                                                            <h2 class="modal-title" id="galleryModalLabel<?php echo $i; ?>"><span id="copyit"><?php echo $image_title['title']; ?></span></h2>
                                                                        </div>
                                                                        <div class="row">
                                                                            <p>keywords: <em><?php if (empty($image_all['alt'])) { echo $image_all['caption']; } else { echo $image_all['alt']; } ?></em></p>
                                                                        </div>
                                                                        <div class="row" id="message">
                                                                            <?php echo do_shortcode( '[gravityform id="1" field_values="filename='. $image_title['title'] .'" ajax="true"]' ); ?>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                            <div class="modal-footer">
                                                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                        <?php $i++; }} wp_reset_postdata(); ?>
                                            </div>

                                            <script type="text/javascript">
                                                jQuery(document).ready(function($) {
                                                    // init Masonry
                                                    var $grid = $('.grid').masonry({
                                                    itemSelector: '.grid-item',
                                                    percentPosition: true,
                                                    columnWidth: '.grid-sizer'
                                                });

                                                // layout Masonry after each image loads
                                                $grid.imagesLoaded().progress( function() {
                                                    $grid.masonry();
                                                });
                                            });

                                            jQuery(document).on("click", "#btnCopy", function(ev) {
                                                var $body = document.getElementsByTagName('body')[0];
                                                var rel = $(this).attr("rel");
                                                var text = $("#"+rel).text();
                                                var $tempInput = document.createElement('INPUT');
                                                $body.appendChild($tempInput);
                                                $tempInput.setAttribute('value',  text)
                                                $tempInput.select();
                                                document.execCommand('copy');
                                                $body.removeChild($tempInput);
                                            });

                                            jQuery(function () {
                                                $('[data-toggle="popover"]').popover().click(function () {
                                                    setTimeout(function () {
                                                        $('[data-toggle="popover"]').popover('hide');
                                                    }, 2000);
                                                });
                                            });
                                        </script>
                                    </div>

                                    <div class="row justify-content-center">
                                        <div class="pagination_links" style="clear: both;">
                                            Page: <?php $big = 999999999; // need an unlikely integer
                                                $translated = __( 'Page', 'ansel' ); // Supply translatable string

                                                echo paginate_links( array(
                                                    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                                                    'format' => '?paged=%#%',
                                                    'current' => max( 1, get_query_var('paged') ),
                                                    'total' => $loop->max_num_pages,
                                                    'before_page_number' => '<span class="screen-reader-text">'.$translated.' </span>'
                                                ) );
                                            ?>
                                        </div>
                                    </div>

                                    <div class="row justify-content-center">
                                        <form class="wpsp-page-nav-form" action="<?php echo $_SERVER['REQUEST_URI'];?>" method="get" style="text-align: center;">
                                            <label for="sortby" class="wpsp-label wpsp-hidden"><?php _e('Jump to', 'wp-smart-pagination'); ?></label>
                                            <div class="input-append" style="display: inline-block;">
                                                <input class="wpsp-input-number" type="text" placeholder="page..."  size="15" name="paged" />
                                                <button class="btn" type="submit"><i class="fa fa-arrow-right" aria-hidden="true"></i></button>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </main>
                    </div>
                </div>
            </div>

    <?php get_footer(); ?>
get_header();
“alt=”“>
关键词:


我在代码中找不到任何问题,因此我进行了一些尝试,并获得了一些解决方法的帮助。因此,我的URL在分页方面没有我希望的那么好,但它们可以工作,这是本例中最重要的一点:

    <?php $big = 999999999;
    for ($i=1;$i<=$loop->max_num_pages;$i++) { ?>
       <a href="<?php str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ) ?>?page=<?php echo $i; ?>" class="page-numbers current" aria-current="page">Page <?php echo $i; ?></a>
    <?php } ?>

我想我会发布我的解决方案,以防其他人需要类似的东西