• 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!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter ssorcdivad

    (@forefront)

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

    Thread Starter ssorcdivad

    (@forefront)

    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.

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

    spencerp

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

    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:

    https://www.vindictivebastard.net/test101/

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

    spencerp

    Thread Starter ssorcdivad

    (@forefront)

    >>>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.

    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 https://pastebin.com or a similar service.

    Thread Starter ssorcdivad

    (@forefront)

    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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Check my code, please?’ is closed to new replies.