• Hi all, I am testing out using wordpress from within my own pages. Currently, I have made a simple test to illustrate some problems I am having.

    https://www.stevelim.com/simple.html

    I have 2 questions.

    #1 You’ll notice at the page here, I have 3 additional blank entries with the words ‘at’ ‘at ‘at’ etc. This text comes from the following code..

    <?php the_time('F j, Y') ?> at <?php the_time() ?>

    Why are there more posts there than entries in that category?

    #2 Am I right to say that wordpress automatically forces each new post content into a element? I ask because if you notice, there are no tags for the content and yet the post content is taking the css property of .

    Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    What’s the actual loop code that you’re using?

    Thread Starter sjlim

    (@sjlim)

    <div id="navBeta">

    <h2>Site</h2>
    <h3>(ToDo/WIP List)</h3>

    <?php $posts = get_posts('numberposts=10&category=12'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <h3><?php the_title(); ?></h3>

    <div class="postmeta">
    <?php the_time('F j, Y') ?> at <?php the_time() ?>
    </div>

    <?php the_content(__('(more...)')); ?>

    <div class="feedback">
    <?php wp_link_pages(); ?>

    </div>
    <?php comments_template(); // Get wp-comments.php template ?>

    <?php endwhile; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>

    <?php endif; ?>
    </div>

    Thread Starter sjlim

    (@sjlim)

    Anyone? The results can be seen in the link posted above.

    I believe the php codeline has to end with a semi-colon <?php the_time(); ?>

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    He’s correct about the need for semi-colons. Also, this doesn’t make a whole lot of sense:

    <?php $posts = get_posts('numberposts=10&category=12'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    What is the get_posts supposed to be doing here? You’ve combined two forms of loops in a rather unusual (and probably non-functional) way. I’m not certain, but this is probably the cause of your problems.

    Use query_posts/have_posts/the_post alone, or use get_posts/foreach/setup_postdata alone, but don’t combine the two forms of loops. That’s just bad karma.

    Thread Starter sjlim

    (@sjlim)

    I have 2 loops on my page. Each loop is supposed to only return the results from a particular category. I am rather php ignorant. Any advice would be appreciated.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    I have 2 loops on my page. Each loop is supposed to only return the results from a particular category.

    Then you want to do something more like this:
    <?php
    query_posts('cat=1'); // first category ID
    if (have_posts()) :
    while (have_posts()) :
    the_post();
    ?>
    // do your post display stuff here
    <?php
    endwhile; endif;
    rewind_posts(); // rewind so we can do a second loop
    query_posts('cat=2'); // second category ID
    if (have_posts()) :
    while (have_posts()) :
    the_post();
    ?>
    // do your post display stuff here
    <?php
    endwhile; endif;
    ?>

    Thread Starter sjlim

    (@sjlim)

    Thanks Otto, I ended up using ‘query_posts’ too from the codex. Thank you!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Trying to use the loop in my own pages/css – problems’ is closed to new replies.