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.

我有WordPress onepage,我在其中一个页面显示了特定类别的帖子。当我点击链接永久链接href时,我正在重定向到主页,添加/ post-name /到url,但没有发布页面。我有index.php和single.php。

I have this index.php:

我有这个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:

此代码按模板部分显示index.php中的所有页面,它正在运行。当我添加到服务页面时,有几个帖子是这样的:

 <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:

此代码无法正常工作,因为当我想点击链接并转到帖子时,网站刷新了url localhost / mywebsite / name-of-post /但我想重定向到帖子页面。我有一个single.php文件:

<?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

怎么了 ?我该如何解决这个问题?我的主题忽略了page.php或single.php等文件

Thanks for help.

感谢帮助。

3 个解决方案

#1


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

您是否也尝试将Wp_Query用于single.php?

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

并且可能尝试将顶部索引中的posts_per_page更改为您的页面数而不是-1。

更多相关文章

  1. php如何跨站抓取别的站点的页面的补充
  2. 在返回按钮上重新加载页面。
  3. ajax在php页面上获得一个值的结果
  4. php使用DOMDocument更改div但不更新页面
  5. 通过添加3hrs从服务器中重新获取CURTIME()并在PHP页面中显示它
  6. 使用jQuery或Javascript重定向到具有值的给定页面
  7. 来自加载页面的Javascript响应未显示在中,尽管我可以在firebug中
  8. 添加到数据库后,保持在同一页面而不刷新它
  9. PHP的页面布局怎样设计

随机推荐

  1. linux设置时间和把时间从UTC转成本地时间
  2. mysqk 5.7官方安装指导,比一般有效
  3. Linux&C网络编程————“聊天室”
  4. Linux内核构建系统之一
  5. Linux 下部署Django项目
  6. 如何使用ffmpeg将m4v和wmv视频转换为mp4
  7. Userspace RCU 安装过程记录
  8. linux c 网络编程, 常用网络函数,范例
  9. Linux 多线程 ”一写多读” 模式下的无锁
  10. Linux命令-权限管理命令:chmod