1

Intro: I have a webpage that is not part of wordpress. I have incorporated the wp blog posts, by putting The Loop in the page's code. This works, it displays the current posts and their following posts up to 3, which is what I set in the wp general options.

On this, non-wp, webpage, I have a sidebar, dubbed "history". Within history I have multiple div boxes, each that I want to contain the last, then next last, and continuing until these divs run out of room in the history div. This is meant to be a dynamic list (with custom images, irrelevant to the question) of blog post titles, a history of posts.

What I have so far: On the first div, in history, I have copied the code from The Loop (that I had copied onto this non-wp webpage). At the top of the page I have "php require('mydomain/xdirectories/home/wp-blog-header.php'). I am able to display the title (and link) of the most recent post and that post's date. These are the only things I want. Here is what the code looks like (this is the first box/div, the second and so on are identical except for the php):

<div class="clean" style="width:132px; height:56px; float:left;">
                <p class="style8" style="width:132px; height:14px;">
                    <?php the_time('F jS, Y') ?>
                </p>
                <p class="style8" style="width:132px; height:42px; 
                text-align:center; font-size:13px; vertical-align:middle;">
                    <span title="Opens in new tab">                         
                        <a href="<?php the_permalink() ?>" target="_blank" rel="bookmark" title="Permanent Link to 
                        <?php the_title_attribute(); ?>">
                        <?php the_title(); ?>
                </a>
                    </span>
                </p>
            </div>

Above is one div, box, that I want to have many of, only with the entry titles of each previous post.

Problem: I cannot figure out how to have the next title, link, and date for any wp blog posts past the first.

Question: How can I get the functions/"php codes" to input into each following div so that it can dynamically generate the second post title, date, and link. Then the third, and so on. Please note, I understand very little of php. I have tried using "the function" codes but it displays nothing. I've put different "php require('x/x/x.php') but more often than not there is an error. What wp page can I refer to with php that has the functions I need? How can I use those?

I need: title, date, link to that post of all the previous posts, dynamically generated so the topmost div always displays the more recent, etc.

Edit: to clarify, I'm looking for a wp php function I can use such as "post title x" where x is the number of the post behind the first. For example, the second box will have "post title 2", the third "post title 3" so it will generate that post title, date, link.

I am sorry if this question is amateurish. Thank you.

1 Answer 1

2

You have to loop through that part of the code to get more posts:

$args = array(
    'posts_per_page' => -1
);
$the_query = new WP_Query( $args );
<?php if ($the_query->have_posts()) : ?>
    <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
        ...<your code>...
    <?php endwhile; ?>
<?php endif; ?>
13
  • Thank you for the response. I thought so too, but the first post title works without that. The loop seems to be for displaying multiple thing(posts/title) in one list. In this case, I just need a function for post title, date, and link and a variable that I can use, ie 2,3,4th post, I can put into each function so each generates a different post title.
    – Cory
    Apr 18, 2013 at 22:38
  • The loop is used to display WP posts,it doesn't really matter which part of the post you want (eg: just the title)
    – ItayXD
    Apr 18, 2013 at 22:43
  • Ok, thanks. I added it to the code. The div is the same code as above, and displays the first posts title, link, and date. Is there a way I can replicate that same thing only with the second, third, and so on posts?
    – Cory
    Apr 18, 2013 at 23:29
  • It still displays only one post? That's weird....
    – ItayXD
    Apr 18, 2013 at 23:33
  • No, you are correct! This works, thank you! However, it will only display the first three post titles. That is the amount of posts I want displayed on the front page(and have set in the wp settings), but I want the "history" section to display every past post, or at least until I say not to (ie 10 posts)
    – Cory
    Apr 18, 2013 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.