• Hi,

    I’m quite new to wordpress and it is great.

    I have used a theme (higherground) as a base template. I have created different templates for different pages but have run into a problem.

    I want to turn off comments for ‘pages’ but not for ‘posts’. I amended articles.php as follows;
    <!-- <?php comments_template(); ?> -->

    The index.php has this code in it;

    <?php get_header(); ?>
    <?php include (TEMPLATEPATH . '/articles.php'); ?>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    The articles.php file is being used for ‘pages’ and ‘posts’. I’ve since created a single.php file (and restored <?php comments_template(); ?>) but I don’t know how to amend the index.php page so that it knows to serve up the single.php file for the blog section.

    Any advice or help with pointing me to the correct documentation would be great.

    Many thanks..

Viewing 7 replies - 1 through 7 (of 7 total)
  • If you don’t have that many pages, this is an easy fix.

    When you create a new Page within wordpress, just scroll to the bottom and uncheck the box that says “Allow Comments.” If you already have your pages created, simply go in as if you were going to edit them, uncheck the box, and then save them.

    You will need to do that for all pages where you want to disable commenting.

    Thread Starter yabai

    (@yabai)

    thanks for the swift reply. i have done this for the pages already (i have quite a few of them…) but the page displays with ‘Comments are closed.’

    <!-- <?php comments_template(); ?> --> was the only way i could see to remove them. that’s what got me thinking about using a template for posts. i’m kicking myself i chose an overly simple theme to edit as it looks like a lot of themes have a separate single.php file that they use.

    cheers

    hold on

    Eep again..

    Since I don’t have a link to your site, I don’t know how many customizations you’ve already done.

    If you want your pages and posts to look differently, it’s much easier to make a page.php and and a single.php so that WordPress will recognize them and use them accordingly.

    If you were editing this template from scratch, this is my recommendation (of course remember to back up everything you had first!):

    Change index.php such that you replace

    <?php include (TEMPLATEPATH . '/articles.php'); ?>

    with this

    <div id="main">
    <?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    			<h1><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
    
    			<?php the_content('Read the rest of this entry &raquo;'); ?>
    
    			<p class="post-footer">
    			<span class="readmore">Posted in: <?php the_category(', ') ?></span> |
    			<span class="comments"><?php $comments_img_link= comments_popup_link($comments_img_link .' Comments(0)', $comments_img_link .' Comments(1)', $comments_img_link . ' Comments(%)');?></span> |
    			<span class="date"><?php the_time('F Y') ?> <?php edit_post_link(__(' Edit')); ?></span>
    			</p>
    			<?php comments_template(); ?>	
    
    			<?php endwhile; ?>
    		<?php else : ?>
    			<h2 align="center">Not Found</h2>
    			<p align="center">Sorry, but you are looking for something that isn't here..</p>
    			<?php endif; ?>
    
    <p align="center"><?php next_posts_link('&laquo; Previous Entries') ?> <?php previous_posts_link('Next Entries &raquo;') ?></p>
    		</div>
    	</div>

    Then make 2 extra copies your new index.php and rename them to page.php and single.php — two natively recognized files that WordPress knows to look for.

    Then open page.php and delete this:

    <p class="post-footer">
    			<span class="readmore">Posted in: <?php the_category(', ') ?></span> |
    			<span class="comments"><?php $comments_img_link= comments_popup_link($comments_img_link .' Comments(0)', $comments_img_link .' Comments(1)', $comments_img_link . ' Comments(%)');?></span> |
    			<span class="date"><?php the_time('F Y') ?> <?php edit_post_link(__(' Edit')); ?></span>
    			</p>

    Eventually you can then delete articles.php since it becomes obsolete. This is how I would do it from scratch. I think I might have had a brain fart there at the end… Just look at the files below. They work on my development machine.

    Here are the exact files that I made on my local machine to test it:
    page.php – https://wordpress.pastebin.ca/1494545
    single.php – https://wordpress.pastebin.ca/1494552
    index.php – https://wordpress.pastebin.ca/1494542

    Sorry bedtime now

    Thread Starter yabai

    (@yabai)

    that looks exactly what i thin i need. you is a star. i’ll have to try this tonight and will then update this post.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘serving separete templates for ‘post’ and ‘pages’’ is closed to new replies.