• Resolved b_obata

    (@b_obata)


    Hi,

    I’m very amateur at this. I’m trying to use WordPress to publish blocks of text on certain pages.

    For instance on this home page: “https://marinifc.org/index.php” I need to publish a post in the left hand column (board members), and publish a block of news in the middle column (sometimes several posts).

    Therefore I created a board list category and a news category, and made entries for each.

    So then I need to know how to populate each block with the different categories’ posts.

    Right now I’m populating the middle block with this code:
    <?php
    require('wp-blog-header.php');
    ?>
    <?php
    $posts = get_posts('numberposts=5&category=5');
    foreach ($posts as $post) : start_wp(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <h2><?php the_title(); ?></h2>

    <div class="entry">
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    <br></div>
    </div>
    <?php endforeach; ?>

    This works fine. However, if I try to re-use the code to get another category, I get the second entry for that category, but not the first. Possibly I should be using something other than get_posts? I’m a definite novice so if anyone could point me in the right direction, that would be great. I actually did read through a lot of the basic documentation – but still am in a bit of a fog about the whole thing.

Viewing 1 replies (of 1 total)
  • Thread Starter b_obata

    (@b_obata)

    i know nothing about this, but found some code that worked.
    In both of the get_posts on the page I had to make the following change:

    Removed this line:
    foreach ($posts as $post) : start_wp(); ?>

    Replaced with this line:
    foreach( $posts as $post ) : setup_postdata( $post ); ?>

    More reading to do.

Viewing 1 replies (of 1 total)
  • The topic ‘Don’t understand how to do get_posts multiple times on same page.’ is closed to new replies.