我对wordpress主题开发很陌生,刚刚开始用bootstrap 3制作一个主题。我在nginx Web服务器上的本地主机上运行wordpress。我创建了index.php文件,并在上面列出了带有阅读更多按钮的帖子,并将它们的标题链接到帖子的永久链接,还创建了single.php。它也工作得很好,但我觉得我的代码有问题。
我的帖子的永久链接是这样的。始终显示index.php
http://www.blog.dev/index.php/%postname
所以我将post的永久链接改为自定义,并删除了"index.php"。之后我的sign.php就不起作用了。我的意思是它给了我一个错误404。
这是我的单曲。php
<!-- Including Header -->
<?php get_header(); ?>
<!-- Post Cover -->
<div id="postCover" class="container-fluid"></div>
<div id="postContainer" class="container">
<div class="col-md-2"></div>
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-heading">
<?php the_title(); ?>
</div>
<div class="panel-body">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('post-thumbnail', array( 'class' => "img-responsive"));
}
?>
<div id="posDetailsContainer" class="container-fluid text-left">
<span>
<i class="fa fa-calendar"></i>
Posted on <?php the_time('M'); ?> <?php the_time('j'); ?> <?php the_time('Y'); ?>
</span>
<span>
<i class="fa fa-comments-o"></i>
<?php comments_number( 'No Comments', '1 Comment', '% Comments' ); ?>
</span>
</div>
<!-- Post Content Display -->
<div id="postContent" class="container-fluid">
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
the_content();
endwhile;
endif;
?>
</div>
</div>
</div>
</div>
<div class="col-md-2"></div>
</div>
如何解决此问题?
谢谢!Srivin Prabhash
我认为您在index.php中犯了一些错误。将此代码放在index.php文件中。
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>
<h5>Posted By : <?php the_author(); ?> | Date : <?php echo the_date('d-m-y'); ?></h5>
<p><?php the_excerpt(); ?></p>
<a href="<?php the_permalink();?>"> Read more </a>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
如果您仍然面临这个问题,请从根目录中删除.htaccess文件并更改永久链接设置。在删除.htaccess文件之前处理备份。
我希望这对你有用。
在根文件夹中添加.htaccess文件,并将此代码粘贴到文件中
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
然后转到设置->永久链接并选择postname。它将工作