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 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题