dongxiusuo9881 2015-05-05 08:41
浏览 40
已采纳

wordpress永久链接重新加载页面,而不是重定向到发布

I have WordPress onepage and I displayed posts from specific category in one of page. When I click to link with permalink href, I am redirecting to home page with added /post-name/ to url, but no to post page. I have index.php and single.php.

I have this index.php:

<?php 
    query_posts(array(
        'post_type' => 'page',
        'posts_per_page' => '-1',
        'order' => 'ASC',
        'orderby' => 'menu_order'
        ));

    $tpl_parts = array(
        '5' => 'about',
        '7' => 'team',
        '76' => 'tech',
        '81' => 'services',
        '101' => 'contact',
        );
 ?>

<?php get_header('home'); ?>


<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <?php if(array_key_exists($post->ID, $tpl_parts)) : ?>

                <?php get_template_part('template-parts/'. $tpl_parts[$post->ID], 'template'); ?>

            <?php else: ?>
                    <section id="<?php echo $post->post_name; ?>">
                    <div class="container">
                        <div class="row">
                            <?php the_content(); ?>
                        </div>
                    </div>  
                    </section>
            <?php endif; ?>

<?php endwhile; else : ?>
<?php endif; ?>


<?php get_footer(); ?>

This code show all pages in index.php by template part, it's working. When I added to services page, a few posts like this:

 <section id="services" class="services-section">
        <div class="container">
            <div class="row">
                <div class="col-xs-12">
                    <h2 class="text-left">Services</h2>
                </div>
            </div>
            <?php $inner_query = new WP_Query( 'category_name=services' ); ?>
            <?php if ( $inner_query->have_posts() ) : while ( $inner_query->have_posts() ) : $inner_query->the_post(); ?>
            <div class="row box-service">
                <div class="col-sm-6 col-xs-12">
                    <?php the_post_thumbnail('full', array('class' => 'img-responsive')); ?>
                </div>
                <div class="col-sm-6">
                    <h3><?php the_title(); ?></h3>
                    <p class="intro"><?php echo the_field('short_caption'); ?></p>
                    <a href="<?php the_permalink(); ?>">More</a>
                </div>
            </div>
            <?php endwhile; else: endif; wp_reset_postdata(); ?>

        </div>
    </section>

This code isn't working, becouse when I want to click on link and go to post, website is refreshing with url localhost/mywebsite/name-of-post/ but I want to redirect to post page. I have a single.php file:

<?php get_header(); ?>


<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<section>
                    <div class="container">
                        <div class="row">
                            <div class="col-xs-12">
                            <h2><?php the_title(); ?></h2>
                                <?php the_content(); ?>
                            </div>
                        </div>
                    </div>  
                    </section>
<?php endwhile; else: endif; ?>


<?php get_footer(); ?>

What's wrong ? How can I fix that ? My theme ignore files like page.php or single.php

Thanks for help.

  • 写回答

3条回答 默认 最新

  • dongou6632 2015-05-05 09:35
    关注

    Are You trying to use Wp_Query to single.php too ?

    And maybe try to change posts_per_page in top index to number of your pages instead of -1.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题