0

I have 3 custom post formats. One is for image, one for video, and, one for gallery besides the default post and they each have a view comments link on the bottom right corner at the end of the post.

Here is the code for that(it's in every formats php file):

<div class="post-comments">
<p class="postcoments"> <a href="<?php comments_link(); ?>"> View responses </p>
</div> --></a> </div>

Check it out here: http://benlevywebdesign.com/wordpress

On the single.php page I would like to get rid/remove the view comments link because you don't need to see it when you are viewing the comments already(its redundant).

I am new at wp and php so I need help

I have already read the wp codex that tells you to just make single.php and single-post_type.php and I didn't work. I am not sure what to do now.

Here is the current loop code in the single.php file: (it says in comment code "You are now viewing single.php" to see if goes to the single.php page as a test)

<!-- GRID 12 You are now viewing single.php -->
<div class="grid_12">

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <?php get_template_part('content', get_post_format()); ?>

<?php endwhile; else: ?>
    <!-- In case no posts were found -->
        <div class="post-cf">Hmmm? Can't. Find. Post.
        </div>
<?php endif; ?>

<!-- CLOSE GRID 12 -->
</div>

2 Answers 2

0

Based on your comment:

I am not trying to detect when I am on a single page but I want to have custom single.php pages like the wp codex says I can by doing single-post_format.php so that I can be able to have control of what you see on the single page for the different post formats(getting rid of the view commenmts link)

The template hierarchy doesn't account for the post format taxonomy with respect to single blog post pages, which have a hierarchy of:

  • single-$posttype.php
  • single.php
  • index.php

All posts that have the post format taxonomy have a $posttype of post. You could use single-post.php, but that really wouldn't help you in this case. You'll want to modify one/all of content-image.php, content-video.php, content-gallery.php, and comments.php.

Based on this comment:

Would I have to take <div class="post-comments"> <p class="postcoments"><a href="<?php comments_link(); ?>"> View responses</p> </div> --></a> </div> out of my content.php and other format type files and stick this in the index.php in between the loop code?

No, not really. I would recommend just wrapping that code in an if ( is_single() ) conditional:

<?php if ( is_single() ) { ?>
    <div class="post-comments"> <p class="postcoments"><a href="<?php comments_link(); ?>"> View responses</p> </div> --></a> </div>
<?php } ?>

That way, the "View Comments" code is not output on single blog post pages, but if the same content-$format.php is used to output Loop content on index.php (for the blog posts index, archive index pages, etc.), the "View Comments" code would still be rendered.

0

You can use is_single() to detect when you are on a single post page. Based on what you've provided I believe you'll want to use that in your content-<post_format>.php template.

6
  • I am not trying to detect when I am on a single page but I want to have custom single.php pages like the wp codex says I can by doing single-post_format.php so that I can be able to have control of what you see on the single page for the different post formats(getting rid of the view commenmts link) Nov 13, 2012 at 18:35
  • Would I have to take <div class="post-comments"> <p class="postcoments"><a href="<?php comments_link(); ?>"> View responses</p> </div> --></a> </div> out of my content.php and other format type files and stick this in the index.php in between the loop code Nov 13, 2012 at 18:38
  • 1
    Where are you seeing that there is a single-post_format.php template? As far as I know there are single-post_type.php templates, but post_formats are handled through get_post_format() etc. Your theme has this set up to be handled via get_template_part('content', get_post_format()); which means that the template would be content-post_format.php. content.php would be the fall-back you can copy it to create new versions for each post format.
    – totels
    Nov 13, 2012 at 19:21
  • Maybe I don't mean single-post_format.php...What I basically want is to be able to hand code the php for the single page for a certain post format instead of using the loop code so I have more control over what It look like Nov 13, 2012 at 23:46
  • You have just as much control in either case. But like I said, if the code you posted is in your single.php you should be able to create content-image.php, content-video.php and content-gallery.php. Assuming those are the names of your post formats.
    – totels
    Nov 14, 2012 at 0:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.