Srivin Prabhash
Srivin Prabhash

Reputation: 123

Wordpress single.php not working when remove index.php from permalink

I'm very new to wordpress theme developing and just started to make a one with bootstrap 3.I'm running wordpress on my localhost on nginx webserver.I created index.php file and make posts listed on it with read more buttons and linked their titles to post's permalinks and created the single.php also.It also working fine but i feel there's something wrong with my codes.

My post's permalinks looks like this.Always showing index.php

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

so i change post's permalinks to custom and removed that "index.php". After that my signle.php doesn't working. I mean it gives me a error 404.

Here's my 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>

How to fix this ?

Thanks ! Srivin Prabhash

Upvotes: 1

Views: 491

Answers (2)

Piyush Dhanotiya
Piyush Dhanotiya

Reputation: 579

Add .htaccess file on root folder and paste this code inside the file

# 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

and then go to setting->permalink and select postname. it will works

Upvotes: 0

vishal patel
vishal patel

Reputation: 329

I think you have done some mistake in index.php. Put this code in your index.php file.

    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(); ?>    

Still if you face this problem remove your .htaccess file from root directory and change permalink setting.Tack backup before delete .htaccess file.

I hope this will work for you.

Upvotes: 1

Related Questions