• acoppard1994

    (@acoppard1994)


    I have the following code displaying on my home page

    <?php 
    
    // connect to database
    $link= mysql_connect("localhost", "USERID", "PASSWORD");
     if (! $link ){
      $dberror= 'Server not available';
      print $dberror;
      return false;
    }
    mysql_select_db('DBNAME', $link);
    if (! mysql_select_db('DBNAME_WP_1', $link)){
      $dberror= mysql_error();
      print $dberror;
      return false;
    }
    $query = "SELECT post_name, post_title, post_content
    FROM wp_posts
    WHERE post_status = 'publish' and post_date <= now()
    ORDER BY post_date DESC
    LIMIT 0 , 5 ";
    $result = mysql_query($query);
    if ( ! $result){
         $dberror = mysql_error();
         print $dberror;
         return false;
     } else {
    //write to page a linked Title and the content. 
    
         while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
      printf("<span><a href='/YOURBLOGURL/%s'>? %s</a> </span> <br />%s<br /><br />",
         $row["post_name"], $row["post_title"], $row["post_content"]);
         } 
    
    }
    ?>

    which displays the most recent 5 posts. It works properly, displays all the posts but the link does not work. I have changed the url. The script thinks that it should be https://www.mydomain.com/journal/postname
    vbut my installation of WordPress 2.1 says that the post should be at
    https://www.mydomain.com/journal/?id=#

    Any help??

Viewing 1 replies (of 1 total)
  • timok

    (@timok)

    $query = "SELECT ID, post_name, post_title, post_content
    FROM wp_posts
    WHERE post_status = 'publish' and post_date <= now()
    ORDER BY post_date DESC
    LIMIT 0 , 5 ";

    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
      printf("<span><a href='/YOURBLOGURL/?id=%s'>? %s</a> </span> <br />%s<br /><br />",
        $row["ID"], $row["post_title"], $row["post_content"]);
    }
Viewing 1 replies (of 1 total)
  • The topic ‘WordPress Working With Some Simple Code’ is closed to new replies.