Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 933223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:47:44+00:00 2026-05-15T20:47:44+00:00

I need to add links to WordPress Posts on a static HTML page. I

  • 0

I need to add links to WordPress Posts on a static HTML page. I got some information that has been helpful but need a few more elements to make it complete.

Here is the code I have so far:

<?php

$number = 5;
$wordpress_header = "blog/wp-blog-header.php";

      // Include wordpress header   
      if (file_exists($wordpress_header))
       {
         include ($wordpress_header);

        $myposts = get_posts('numberposts=$number&offset=0&category=0');

        echo "<ul class='Bloglinks'>";

        foreach(array_slice($myposts, 0, $number) as $post) 
         {
            echo '<li><a href="';
            the_permalink();
            echo '">';
            the_date();
            echo " ";
            the_title();
            echo '</a></li>';
         }

         echo "</ul>";

       }
       else
       {
         echo "Unable to connect to WordPress header file.";
         die();
       } 

?>  

This only shows the titles of the most recent posts. I need to be able to display the following:

<h5>The truth about Lazy Eye</h5>
<p class="blog-info">07.16.10 | <a class="comment-ref">3 Comments</a></p>
<h5>More Adult Learning Problems Linked to Eyes</h5>
<p class="blog-info">06.12.10 | <a class="comment-ref">1 Comments</a></p>
<h5>New Vision Examination Instruments Arrived!</h5>
<p class="blog-info">05.10.10 | <a class="comment-ref">13 Comments</a></p>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:47:45+00:00Added an answer on May 15, 2026 at 8:47 pm

    You should use the function query_posts() with the functions have_posts() and the_post(). Here is an example for the WordPress API:

    //The Query
    query_posts('posts_per_page=5');
    
    //The Loop
    if ( have_posts() ) : while ( have_posts() ) : the_post();
     ..
    endwhile; else:
     ..
    endif;
    
    //Reset Query
    wp_reset_query();
    

    That will loop through all posts you have queried. So you can just insert your query from the get_posts() function into the query_posts() function.

    EDIT: I think if you want to stick with the get_posts() function, you have to call the setup_postdata() function to get the new post (source code for the API):

    <ul>
        <?php
            global $post;
            $myposts = get_posts('numberposts=5&offset=1&category=1');
            foreach($myposts as $post) :
                setup_postdata($post);
        ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <?php endforeach; ?>
    </ul> 
    

    But I would recommend to take the query_posts() function instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that I am trying to dynamically add some links to.
I need to add two lines of html to every page on a large
I need to make a table such that the user can add attachment links
I have a varying number of links that I need to add to a
I have a WordPress site with a form that I need to add a
I need to add HTML to the Category names within my Wordpress theme, so
I need add a new user group for mediawiki. The new group has more
need to add a 2nd css stylesheet to a page. do i add a
I'm using a bit of jQuery to expand/hide some divs. I need to add
using a twitter display widget and need to add links to the hash tags.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.