Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.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 Wordpress-永久链接设置停止页面模板工作_Php_Wordpress_Templates_Custom Post Type_Permalinks - Fatal编程技术网

Php Wordpress-永久链接设置停止页面模板工作

Php Wordpress-永久链接设置停止页面模板工作,php,wordpress,templates,custom-post-type,permalinks,Php,Wordpress,Templates,Custom Post Type,Permalinks,我即将完成一个wordpress站点,它有一个自定义主题和几个自定义帖子类型。现在我想将permalink设置更改为%post name%,以使url更好,这就是问题的根源 在默认的帖子格式旁边,我有3种自定义的帖子类型:事件、画廊、商店。现在,当我加载页面“事件”(使用template-events.php,wp_查询如何获取所有事件)时,我得到了所有帖子。它基本上忽略了定义的模板并加载了为帖子页面定义的模板,商店页面也是如此。 奇怪的是,gallery页面(加载相同类型的模板文件来执行wp_

我即将完成一个wordpress站点,它有一个自定义主题和几个自定义帖子类型。现在我想将permalink设置更改为%post name%,以使url更好,这就是问题的根源

在默认的帖子格式旁边,我有3种自定义的帖子类型:事件、画廊、商店。现在,当我加载页面“事件”(使用template-events.php,wp_查询如何获取所有事件)时,我得到了所有帖子。它基本上忽略了定义的模板并加载了为帖子页面定义的模板,商店页面也是如此。 奇怪的是,gallery页面(加载相同类型的模板文件来执行wp_查询)工作正常

当我更改回默认的永久链接设置时,一切正常

谢谢你的提示

这里是我的模板-events.php

<?php 
/*
Template Name: Events
*/
?>

<?php get_header(); ?>



        <?php


        //Fix homepage pagination
        if ( get_query_var('paged') ) {
            $paged = get_query_var('paged');
        } else if ( get_query_var('page') ) {
            $paged = get_query_var('page');
        } else {
            $paged = 1;
        }

        $now = strtotime("now");

        $args = array(
            'post_type' => 'events',
            'posts_per_page' => 40,
            'post_status' => 'publish',
            'meta_key' => '_cmb_date_timestamp',
            'orderby' => 'meta_value',
            'order' => 'ASC',
            'paged' => $paged,
            'meta_query' => array(
                array(
                    'key' => '_cmb_date_timestamp',
                    'value' => $now,
                    'type' => 'NUMERIC',
                    'compare' => '>='               )
            )               
        );

        // Create a new filtering function that will add our where clause to the query
        function filter_where( $where = '' ) {
            // posts in the last 30 days
            $where .= " AND _cmb_date_timestamp  < '" . date('Y-m-d') . "'";
            return $where;
        }

        //add_filter( 'posts_where', 'filter_where' );

        $events_query = new WP_Query($args);

        if( $events_query->have_posts() ) : 
            $derLudwig = get_theme_mod( 'eventsHeading', '');
            $url = esc_url( get_theme_mod( 'events_image' ) );
            echo '<div class="overview-header" style="background-image: url('.$url.');"></div>';
            echo '<a href="'.get_home_url().'"><h2 class="overview">der Ludwig '.$derLudwig.'</h2></a>';

            ?>

            <div id="filters">
                <div id="filterButtons">
                    <a id="filterOpen" class="filterB" href="#"><img src="<?php echo get_bloginfo("template_url"); ?>/images/sub-navi2.png"/></a>
                    <a id="filterClose" class="filterB" href="#"><img src="<?php echo get_bloginfo("template_url"); ?>/images/filter-close.png"/></a>
                </div>
                <?php

                /* FILTERS */

                $args = array(
                  'type' => 'events',
                  'taxonomy' => 'event_category',
                  'orderby' => 'name',
                  'order' => 'ASC'
                  );
                $categories = get_categories($args);
                echo '<div id="categories">';
                    echo '<h5>Kategorien: </h5>';
                    echo '<ul>';
                    foreach ($categories as $category) {
                        echo '<li><a href="#" class="filterLink ajax" onclick="term_ajax_get('.$category->term_id.')">' . $category->name . '</a></li>';
                    }
                    echo '</ul>';
                echo '</div>';

                ?>

                <a href="#"  class="clearFilter filterLink ajax" onclick="term_ajax_get('-')">Clear</a>

            </div>

        <!--BEGIN #content -->
        <div id="content" class="clearfix">



        <?php
            echo '<img class="loader" src="'.get_bloginfo('template_url').'/images/loader.gif"/>';  
            echo '<div id="primary" class="hfeed event-overview">';

            while( $events_query->have_posts() ) : $events_query->the_post();

            // infos
            $time = get_post_meta($post->ID, '_cmb_time', true);
            $cdateStamp = get_post_meta($post->ID, '_cmb_date_timestamp');

            $monthName = date_i18n('F', $cdateStamp[0]);
            $weekdayNumber = date_i18n('j', $cdateStamp[0]);
            $weekday = date_i18n('D', $cdateStamp[0]);

            $locations = get_the_terms( $post->ID, 'locations' );
            $tickets = get_post_meta($post->ID, '_ludwig_events_tickets', true);
            $featured = get_post_meta($post->ID, '_ludwig_events_display_featured', true);
            $reservation = get_post_meta($post->ID, '_ludwig_events_display_reservation', true);

            // grab everything else
            $custom_bg = get_post_meta($post->ID, '_zilla_portfolio_display_background', true);
            $portfolio_caption = get_post_meta($post->ID, '_zilla_portfolio_caption', true);


            ?>
            <?php
            if(!isset($currentMonth) || $currentMonth != $monthName){
            ?>
            <h2 class="<?php echo lcfirst($monthName); ?>"><?php echo $monthName; ?></h2>



            <?php
            }
            $currentMonth = $monthName;
            ?>

            <!--BEGIN .hentry-->
            <div id="post-<?php the_ID(); ?>" class="event-small <?php echo lcfirst($monthName); ?>">

                <!--BEGIN .entry-content -->
                <div class="entry-content">
                    <div class="eTop">
                        <span class="dateDay"><?echo $weekdayNumber; ?></span>
                        <span class="dateMonth"><? _e($monthName, 'ludwig-events'); ?></span>
                        <span class="dateWeekDay"><? _e($weekday, 'ludwig-events'); ?></span>
                    </div>
                    <a href="<?php echo get_permalink(); ?>"><?php the_post_thumbnail('event-small'); ?></a>
                    <div class="eBottom">
                        <a href="<?php echo get_permalink(); ?>"><?php the_title('<h3>', '</h3>'); ?></a>
                        <span class="eventWo">
                            <?php 

                            if ( $locations && !is_wp_error( $locations ) ) {
                               foreach ( $locations as $location ) {
                                  echo $location->name;
                               }
                            } 
                            ?>
                            , <?php echo $time; ?>Uhr</span>

                         <div class="event-buttons">    
                            <div class="inner">
                                <div class="centerContainer">
                                    <h4>Tickets</h4>
                                    <?php ticketsLink($tickets); ?>
                                    <?php reservationLink($reservation); ?>
                                </div>
                            </div>
                        </div>
                    </div>
                <!--END .entry-content -->

                </div>


            </div>


            <?php endwhile; ?>

            <!--END #primary .hfeed-->
            </div>


        <?php else: ?>

        <div id="content" class="nocontent">
            <!--BEGIN #post-0-->
            <div id="post-0" <?php post_class(); ?>>

                <h2 class="entry-title"><?php _e('Keine Events gefunden', 'ludwig') ?></h2>

                <!--BEGIN .entry-content-->
                <div class="entry-content">
                    <p><?php _e("Hoppala, das sollte eigentlich nicht passieren", "ludwig") ?></p>
                <!--END .entry-content-->
                </div>

            <!--END #post-0-->
            </div>
        </div>

        <?php endif; ?>

        <?php remove_filter( 'posts_where', 'filter_where' ); ?>



<?php get_footer(); ?>

我的提示(因为您没有输入代码):

permalink并没有问题。它应该可以工作。我相信这是您的代码造成的。请仔细检查您的代码并重新安装WordPress,然后重试

<?php 
/*
Template Name: Fotos
*/
?>

<?php get_header(); ?>



        <?php


        //Fix homepage pagination
        if ( get_query_var('paged') ) {
            $paged = get_query_var('paged');
        } else if ( get_query_var('page') ) {
            $paged = get_query_var('page');
        } else {
            $paged = 1;
        }

        // CHECK THAT THIS ONE ISTN DOWN
        /*
        $args = array(
                'post_type' => 'gallery',
                'posts_per_page' => 1,
                'post_status' => 'publish',
                'orderby' => 'modified',
                'order' => 'ASC',
                'tax_query' => array(
                    array(
                        'taxonomy' => 'gallery_category',
                        'field' => 'id',
                        'terms' => array( $term_id ),
                        'operator' => 'IN'
                    )
                ),
                'paged' => $paged
        );
        $sina_query = new WP_Query($args);

        $sinaString = '';

        if( $posts_query->have_posts() ) : 
            while( $posts_query->have_posts() ) : $posts_query->the_post();
        ?>

            <?php endwhile; ?>
        <?php endif; ?>
    */



        $args = array(
            'post_type' => 'gallery',
            'orderby' => 'modified',    
            'order' => 'DESC',
            'posts_per_page' => 10,
            'paged' => $paged
        );
        $posts_query = new WP_Query($args);

        if( $posts_query->have_posts() ) : 
            $derLudwig = get_theme_mod( 'fotosHeading', '');
            $url = esc_url( get_theme_mod( 'fotos_image' ) );
            echo '<div class="overview-header" style="background-image: url('.$url.');"></div>';
            echo '<a href="'.get_home_url().'"><h2 class="overview">der Ludwig '.$derLudwig.'</h2></a>';
            ?>


    <div id="filters">
        <div id="filterButtons">
            <a id="filterOpen" class="filterB" href="#"><img src="<?php echo get_bloginfo("template_url"); ?>/images/sub-navi2.png"/></a>
            <a id="filterClose" class="filterB" href="#"><img src="<?php echo get_bloginfo("template_url"); ?>/images/filter-close.png"/></a>
        </div>
        <?php

        /* FILTERS */ 

        $args = array(
          'type' => 'events',
          'taxonomy' => 'gallery_category',
          'orderby' => 'name',
          'order' => 'ASC'
          );
        $categories = get_categories($args);
        echo '<div id="categories">';
            echo '<h5>Kategorien: </h5>';
            echo '<ul>';
            foreach ($categories as $category) {
                echo '<li><a href="#" class="filterLink ajax" onclick="term_ajax_get('.$category->term_id.')">' . $category->name . '</a></li>';
            }
            echo '</ul>';
        echo '</div>';

        ?>

        <a href="#"  class="clearFilter filterLink ajax" onclick="term_ajax_get('-')">Clear</a>

    </div>


    <!--BEGIN #content -->
    <div id="content" class="clearfix">

            <?php
            echo '<img class="loader" src="'.get_bloginfo('template_url').'/images/loader.gif"/>';      

            echo '<div id="primary" class="hfeed gallery-overview">';

            $counter = 0;

            while( $posts_query->have_posts() ) : $posts_query->the_post();

            $fotograf = get_post_meta($post->ID, '_ludwig_gallery_fotograf', true);
        ?>
                <?php
                if ($counter == 1) {
                ?>


<div id="post-<?php the_ID(); ?>" class="gallery-grid post-<?php echo $counter++; ?>">

                <!--BEGIN .entry-content -->
                <div class="entry-content">
                     <a href="<?php echo get_permalink(); ?>">
                    <div class="overlayContainer">
                        <div class="overlay">
                            <div class="content">
                                <div class="inner">
                                <?php
                                /*
                                $terms = get_the_terms( $post->ID, 'gallery_category');

                                if ( $terms && ! is_wp_error( $terms ) ) : 

                                    $draught_links = array();

                                    foreach ( $terms as $term ) {
                                        $draught_links[] = $term->name;
                                    }

                                    $on_draught = join( ", ", $draught_links );
                                    */
                                ?>

                                <p class="galleryCategories">
                                    <span><?php //echo $on_draught; ?></span>
                                </p>

                                <?php //endif; ?>
                                <h3><?php the_title(); ?></h3>
                                <p class="fotograf">von<br><span><?php echo $fotograf; ?></span></p>
                                </div>
                            </div>
                        </div>
                    </div>
                   <?php the_post_thumbnail('gallery-mid'); ?></a>
                </div>
                </div>             

                <?php echo $counter++; ?>
                <?php
                } else {
                ?>
                <div id="post-<?php the_ID(); ?>" class="gallery-grid post-<?php echo $counter++; ?>">

                <!--BEGIN .entry-content -->
                <div class="entry-content">
                     <a href="<?php echo get_permalink(); ?>">
                    <div class="overlayContainer">
                        <div class="overlay">
                            <div class="content">
                                <div class="inner">
                                <?php
                                /*
                                $terms = get_the_terms( $post->ID, 'gallery_category');

                                if ( $terms && ! is_wp_error( $terms ) ) : 

                                    $draught_links = array();

                                    foreach ( $terms as $term ) {
                                        $draught_links[] = $term->name;
                                    }

                                    $on_draught = join( ", ", $draught_links );
                                    */
                                ?>

                                <p class="galleryCategories">
                                    <span><?php //echo $on_draught; ?></span>
                                </p>

                                <?php //endif; ?>
                                <h3><?php the_title(); ?></h3>
                                <p class="fotograf">von<br><span><?php echo $fotograf; ?></span></p>
                                </div>
                            </div>
                        </div>
                    </div>
                   <?php the_post_thumbnail('gallery-mid'); ?></a>
                </div>
                </div>             

                <?php } ?>


            <?php endwhile; ?>

            <!--END .hfeed -->
            </div>
            <a class="archivlink" href="#">⌸ Archiv</a>

            <div class="navigation">
                <div class="next-posts"><?php next_posts_link('&laquo; Older Entries', $posts_query->max_num_pages) ?></div>
                <div class="prev-posts"><?php previous_posts_link('Newer Entries &raquo;', $posts_query->max_num_pages) ?></div>
            </div>

            <?php else: ?>

                <div id="content" class="nocontent">
                    <!--BEGIN #post-0-->
                    <div id="post-0" <?php post_class(); ?>>

                        <h2 class="entry-title"><?php _e('Keine Fotos gefunden', 'ludwig') ?></h2>

                        <!--BEGIN .entry-content-->
                        <div class="entry-content">
                            <p><?php _e("Hoppala, das sollte eigentlich nicht passieren", "ludwig") ?></p>
                        <!--END .entry-content-->
                        </div>

                    <!--END #post-0-->
                    </div>
                </div>

        <?php endif; ?>

<?php get_footer(); ?>