WordPress.org

Support

Support » How-To and Troubleshooting » Stupid Question, please help

Stupid Question, please help

  • Hello. I searched the codex and the old wiki before posting this, I am not a programmer (maybe the problem)

    I want to constrain the loop so that it only displays posts and comments which match a specific ID.

    If this is how I would constrain by category…

    <?php if ( (in_category('2')) ) { ?>

    …Then how do I request just the content and comments from a specific post? I know this is easy, hope you can help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • post ID that is, …. trying to substitute “the_ID” for “in_category” doesn’t seem to work.

    Review the documentation for query_posts(). If you still have questions, ask them here!

    I have been studying it for a few hours now, I think I need someone to throw me a line here. I just need the code I can paste into a flat file and get the contents of a specific post (by pinpointing it’s ID), and then below that post to have the comments and the comment form. It should be easy, but I think WP’s template system obscure’s this a bit – at least for someone who doesn’t really know PHP.

    I have figured out how to get just a specific post to show up, thanks to your help skippy. This is as far as I am with it.


    <?php query_posts('p=1'); //retrieves post with ID 1 ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php if ( (in_category('2')) ) { ?>

    <div class="post">
    <h3><?php the_title(); ?></h3>
    <div class="entry">
    <?php the_content(); ?>
    <small>last edited: <?php the_time('F jS, Y'); ?></small>
    </div>
    </div>
    <?php } ?>

    <?php endwhile; else: ?>
    Sorry, no posts matched your criteria.
    <?php endif; ?>

    I have a loop limited by post ID, and…er..also by category, just for the hell of it. Now when I try to display comments it goes all wrong. I need to copy and paste in some code from another template – can someone just tell me which one? Essentially, what I want is to replicate the perma link page., only constraining it to a specific post ID. If you can give me any help I’d really appreciate it!

    d

    Can you explain what you mean by “when I try to display comments it goes all wrong”? Does your current file call comments_template()?

    Yeps, sorry. That was pretty unclear.

    My current file did not contain “comments_template()” – nor that it does things are working better.

    Can anyone now tell me, what code does “comments_template()” spit out? I would like be able to edit the code myself. Is there a physical template or chunk of code I can paste in that does the same thing as comments_template() ???

    thx.
    d

    from the codex:

    <?php comments_template() ?>:
    This tag includes the file comments.php from your current theme’s directory. If that file is not found, it will instead include wp-content/themes/default/comments.php.

    Since I’m not using themes I probably just need to edit this file.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Stupid Question, please help’ is closed to new replies.