WordPress.org

Ready to get started?Download WordPress

Forums

Check my code, please? (9 posts)

  1. forefront
    Member
    Posted 8 years ago #

    Hi,

    I (no programmer!) am doing my first WP site and wondered if someone could check the code of these three templates for any obvious mistakes.

    The site is more of a "traditional" website managed with WP than a blogging site, as such.

    1: index.php - used in conjunction with a plugin to make a single post my home page.

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php the_content(''); ?>
    <?php endwhile; ?>
    <?php else : ?>
    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.</p>
    <?php endif; ?>

    2: category.php - prints a list of articles within the current category:

    <h2><?php single_cat_title(); ?></h2>
    <p>
    <?php echo(category_description(the_category_ID(false))); ?>
    </p>
    <ul>
    <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
    <li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a><br/>
    <?php the_excerpt(); ?>
    </li>
    <?php endforeach; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?></ul>

    3: single.php - when someone clicks on any post this is the template:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>
    <?php endwhile; else: ?>
    <p>Sorry, no posts matched your criteria.</p>
    <?php endif; ?>

    Thank you!

  2. forefront
    Member
    Posted 8 years ago #

    Is there a better way for me to display the code for this?

  3. forefront
    Member
    Posted 8 years ago #

    Hi,

    I am new here and this is my first set of simple templates using WordPress. Am I posting this in the wrong place to get a response?

    Thank you.

  4. spencerp
    Member
    Posted 8 years ago #

    You're posting parts of the Existing WordPress Files, and what you like to do them?

    spencerp

  5. spirit892
    Member
    Posted 8 years ago #

    I'm a little confused. Is there a problem with the code, or would you like a review of your site?

  6. spencerp
    Member
    Posted 8 years ago #

    spirit, I think they want to be able to print some stuff via catagory..I just went through again:
    "2: category.php - prints a list of articles within the current category:"

    Which I'm not sure about, because GamerZ plugin does if for each post, I'm not sure about full "PAGES" worth of content. Or even just the content that you want printed from the Catagories..I never did that before. But GamerZ could help then, when he gets online...

    For this: "1: index.php - used in conjunction with a plugin to make a single post my home page."
    You'd almost want a sticky plugin, which makes your homepage post, in all pages...or just add a <div> section to the header.php .....like I did here:

    http://www.vindictivebastard.net/test101/

    As for number three, there is and should be a template ready to go for each page...

    spencerp

  7. forefront
    Member
    Posted 8 years ago #

    >>>I'm a little confused. Is there a problem with the code, or would you like a review of your site?

    Hi,

    I created three templates (above) and wanted someone to review the code for correctness and advise any changes/improvements.

  8. moshu
    Member
    Posted 8 years ago #

    What you posted above - are NOT templates, just snippets of code. Take a working theme and see how a complete template file is done.

    Do not post long code here - use http://pastebin.com or a similar service.

  9. forefront
    Member
    Posted 8 years ago #

    I took a working them and edited it then I took the code I wanted checked from the templates I created and pasted that, trying to avoid posting long code.

    If anyone can actually say whether the PHP code in these three code samples look correct, with loops in the correct place, I'd be grateful.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.