【问题标题】:Wordpress single.php not working when remove index.php from permalink从永久链接中删除 index.php 时,Wordpress single.php 不起作用
【发布时间】:2016-07-19 12:41:17
【问题描述】:

我对 wordpress 主题开发非常陌生,刚刚开始使用 bootstrap 3 制作一个。我在 nginx webserver 上的本地主机上运行 wordpress。我创建了 index.php 文件并在上面列出了帖子阅读更多按钮并将它们的标题链接到帖子的永久链接,并创建了 single.php。它也可以正常工作,但我觉得我的代码有问题。

我的帖子的永久链接看起来像这样。总是显示 index.php

http://www.blog.dev/index.php/%postname

所以我将帖子的永久链接更改为自定义并删除了“index.php”。之后我的signle.php 不起作用。我的意思是它给了我一个错误 404。

这是我的single.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>&nbsp;
                        Posted on <?php the_time('M'); ?>&nbsp;&nbsp;<?php the_time('j'); ?>&nbsp;&nbsp;<?php the_time('Y'); ?>
                    </span>
                    <span>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <i class="fa fa-comments-o"></i>&nbsp;
                        <?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>

如何解决这个问题?

谢谢! 斯里文·普拉巴什

【问题讨论】:

  • 您是如何更改永久链接的?在永久链接设置中?
  • @dingo-d 是的先生。我制作了永久链接自定义并从中删除了 index.php 部分。谢谢!
  • 您的 .htaccess 文件看起来如何?请粘贴。 .htaccess 文件甚至存在于您的 wordpress CMS 的根文件夹中吗?

标签: php wordpress


【解决方案1】:

我认为你在 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 文件之前进行备份。

我希望这对你有用。

【讨论】:

    【解决方案2】:

    在根文件夹中添加 .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
    

    然后转到设置->永久链接并选择帖子名称。它会起作用的

    【讨论】:

      猜你喜欢
      • 2011-05-22
      • 2011-05-18
      • 2015-07-03
      • 2021-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多