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