• I have a couple custom templates for a site I am building and using a static page for home, and custom template for blog posts page. The post page is set in ‘reading’ settings, but the posts display using index.php. Here is the code of the template I want to use for the posts page. Any thoughts? Thank you!

    <?php/*Template Name: Blog Page*/?>
    <?php get_header(); ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    	<div class="post" id="post-<?php the_ID(); ?>"><!--start post-->
    
    			<h2><?php the_title(); ?></h2>
    
    			<div id="main_full" class=" clearfix"><!--start main-->
    
    				<div id="top_bar"><h3 class="gallery-title"><span>otto</span>williams | community | news</h3></div>
    
    					<div id="blog_page"><!--start blog page-->
    
    						<div class="entry"><!--start entry-->
    
    							<?php the_content(); ?>
    
    						</div><!--end entry-->
    
    					</div><!--end blog page-->
    
    			</div><!--end main-->
    
    		<?php endwhile; endif; ?>
    
    		<?php get_sidebar(); ?>
    
    		</div><!--end post-->
    
    	<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    
    	<?php comments_template(); ?>
    
    <?php get_footer(); ?>

Viewing 15 replies - 1 through 15 (of 15 total)
  • If your home page is the blog page your site will use index.php. The solution is to create your own index.php or use Conditional Tags to have the home page display a particular way without affecting any other pages that might use the index.php template.

    Thread Starter thatryan

    (@thatryan)

    The home page is not the blog page. The home page is a static page, and uses its own template.

    First, I’d have you check out this documentation to make sure you set your settings correctly:

    http://codex.wordpress.org/Settings_Reading_SubPanel

    Make sure your files are not named one of the banned file names:

    http://codex.wordpress.org/Theme_Development#Theme_Template_Files_List

    Thread Starter thatryan

    (@thatryan)

    Thanks, but yeah the settings are correct and not using any of those names. File names are homepage.php and postings.php. homepage.php is set as the template for my page named “home” and postings.php is set as the template for my paged named “blog”. In reading settings, the static button is checked and the page “home” is selected in the dropdown. And for posts page, the “blog” page is chosen.
    This is why I am so confused..

    Thread Starter thatryan

    (@thatryan)

    Ok wait I stumbled on this, http://codex.wordpress.org/Creating_a_Static_Front_Page#Creating_a_Static_Front_Page Can you NOT use a custom page template as the posts page?!?!?

    Basically the issue seems to be that you created a Page Template, created a page called Home (or whatever) in admin, assigned your Page Template to it, but it is displaying via index.php instead, right? I don’t think the question is about creating a static front page.

    Sorry, I forgot it’s not the home page but it is the blog page. It still seems like you would want to edit the theme file (use your code rather than the original) rather than creating a Page Template and assigning it to the page in admin.

    Thread Starter thatryan

    (@thatryan)

    No. lol. I have made about 7 custom templates for this site theme. Each page has a different one, and the homepage is display the homepage.php template as a static page, like it should. However, the template I created to be used for the postings page, ie, the blog, is not being used, it is instead displaying the blog posts on index.php.

    I know those two are meant to do almost the same thing but if one doesn’t work maybe the other one will.

    Yes I understand now. Does your theme have a page.php? If not, try creating that and putting your code into it so that it will be your default page template instead of applying the template in admin.

    Thread Starter thatryan

    (@thatryan)

    I built the theme so I just made one. πŸ™‚ I did not know that custom templates could not be used for the “posts” page. Wow fail. πŸ˜‰
    Is it better than to put the code in page.php or index.php? It was grabbing index.php not page…

    If you don’t have a pagename.php, page-slug.php, page-id.php, or page.php, WordPress will default to index.php as the default page template. See the page Hierarchy chart here:

    http://codex.wordpress.org/images/1/18/Template_Hierarchy.png

    Thread Starter thatryan

    (@thatryan)

    yeah I read that. But what confuses me is that I have both, page.php and index.php. I copied index.php exactly (because it was working) and put it in page.php. Refresh but index.php is still used.

    I just realized that page.php is not the page template for the default blog page πŸ™

    Looking at the chart it seems like creating home.php may do the trick. If not, you could put your code into index.php. In that case you might want to use Conditional Tags.

    Sorry, I guess I’m getting tired. Time to hang it up for the night.

    So, again it is not your home page (I guess I was pretty tired) so home.php wouldn’t work. You probably would have to put your code into index.php after all. That being the case you might want to make your code conditional using if (is_home()) or if if (is_page('whatever')).

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Posts going to index.php instead of custom template’ is closed to new replies.