wordpress 永久链接重新加载页面而不是重定向到 post
wordpress permalink reload page and not redirect to post
我有 WordPress 一个页面,我在其中一个页面中显示了来自特定类别的 posts。
当我使用 permalink href 单击 link 时,我重定向到主页,添加了 /post-name/ 到 url,但没有添加到 post页。我有 index.php 和 single.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(); ?>
此代码按模板部分显示 index.php 中的所有页面,它正在运行。
当我添加到服务页面时,一些 post 是这样的:
<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>
此代码无效,因为当我想单击 link 并转到 post 时,网站正在刷新 url localhost/mywebsite/name-of-post/ 但我想要重定向到 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(); ?>
怎么了?我该如何解决?我的主题忽略 page.php 或 single.php
等文件
感谢您的帮助。
您可以尝试显示单个 post 页面。
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a>
</h2>
<div class="entry">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; ?>
您是否也想使用 Wp_Query 到 single.php?
也许尝试将顶部索引中的 posts_per_page 更改为您的页数而不是 -1。
好吧,在这个问题上花了几个小时后,我试图找到为什么 page.php 和 single.php 被忽略的原因。
Polylang 插件 - 关闭后。一切正常。
谢谢大家的帮助。
我有 WordPress 一个页面,我在其中一个页面中显示了来自特定类别的 posts。 当我使用 permalink href 单击 link 时,我重定向到主页,添加了 /post-name/ 到 url,但没有添加到 post页。我有 index.php 和 single.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(); ?>
此代码按模板部分显示 index.php 中的所有页面,它正在运行。 当我添加到服务页面时,一些 post 是这样的:
<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>
此代码无效,因为当我想单击 link 并转到 post 时,网站正在刷新 url localhost/mywebsite/name-of-post/ 但我想要重定向到 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(); ?>
怎么了?我该如何解决?我的主题忽略 page.php 或 single.php
等文件感谢您的帮助。
您可以尝试显示单个 post 页面。
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a>
</h2>
<div class="entry">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; ?>
您是否也想使用 Wp_Query 到 single.php?
也许尝试将顶部索引中的 posts_per_page 更改为您的页数而不是 -1。
好吧,在这个问题上花了几个小时后,我试图找到为什么 page.php 和 single.php 被忽略的原因。
Polylang 插件 - 关闭后。一切正常。
谢谢大家的帮助。