Wallpaper Script Forum » Plugins and Hacks

Adding Wordpress Latest Post on Main Page of Wallpaper Script

(4 posts)
  1. Asalam o Alikum

    Since long i was trying to search this post, here i am thankful to http://www.seochat.com/c/a/Search-Engine-Optimization-Help/Display-Recent-Posts-Outside-Your-Wordpress-Blog-Installation/3/ or easy tutorial at http://codex.wordpress.org/Integrating_WordPress_with_Your_Website

    which worked perfectly for me to display latest wordpress post on wallpaper script main page. you can format it as much as you can just place the given code on any main.tpl or index.tpl definging heaads etc

    you can see live test at www.pakislam.com main page

    Posted 1 year ago #
  2. Code

    <?php

    //connect to database

    $username = "Put your Wordpress database username here";

    $password = "Put your Wordpress database password here";

    $hostname = "Put your database hostname here";

    $database = "Put your database name here";

    $dbhandle = mysql_connect($hostname, $username, $password)

    or die("Unable to connect to MySQL");

    $selected = mysql_select_db($database,$dbhandle)

    or die("Could not select $database");

    //find the latest post ID with post status set to publish

    $resultmax = mysql_query("SELECT max(ID) from

    _
    where
    s
    ='publish'") or die(mysql_error());

    $rowmax = mysql_fetch_array($resultmax) or die("Invalid query" . mysql_error());

    $maximum = $rowmax['max(ID)'];

    //find the second latest post ID with post status set to publish

    $resultmiddle = mysql_query("SELECT max(ID) from

    _
    where
    s
    ='publish' and
    <'$maximum'") or die(mysql_error());

    $rowmiddle = mysql_fetch_array($resultmiddle) or die("Invalid query" . mysql_error());

    $middle = $rowmiddle['max(ID)'];

    //find the third latest post ID with post status set to publish

    $resultmin = mysql_query("SELECT max(ID) from

    _
    where
    s
    ='publish' and
    <'$middle'") or die(mysql_error());

    $rowmin = mysql_fetch_array($resultmin) or die("Invalid query" . mysql_error());

    $low = $rowmin['max(ID)'];

    //mysql real escape string to prevent MySQL injection

    $maximum=mysql_real_escape_string(stripslashes($maximum));

    $middle=mysql_real_escape_string(stripslashes($middle));

    $low=mysql_real_escape_string(stripslashes($low));

    //retrieve title tags for latest post

    $resulttitlemax = mysql_query("SELECT

    s
    FROM
    _
    WHERE
    ='$maximum'")

    or die(mysql_error());

    $rowtitlemax = mysql_fetch_array($resulttitlemax)

    or die("Invalid query: " . mysql_error());

    $titlemax = $rowtitlemax['post_title'];

    //retrieve title for second latest post

    $resulttitlemiddle = mysql_query("SELECT

    s
    FROM
    _
    WHERE
    ='$middle'")

    or die(mysql_error());

    $rowtitlemiddle = mysql_fetch_array($resulttitlemiddle)

    or die("Invalid query: " . mysql_error());

    $titlemiddle = $rowtitlemiddle['post_title'];

    //retrieve title for third latest title tag

    $resulttitlemin = mysql_query("SELECT

    s
    FROM
    _
    WHERE
    ='$low'")

    or die(mysql_error());

    $rowtitlemin = mysql_fetch_array($resulttitlemin)

    or die("Invalid query: " . mysql_error());

    $titlelow = $rowtitlemin['post_title'];

    //retrieve URL for latest post

    $resulturlmax = mysql_query("SELECT

    i
    FROM
    _
    WHERE
    ='$maximum'")

    or die(mysql_error());

    $rowurlmax = mysql_fetch_array($resulturlmax)

    or die("Invalid query: " . mysql_error());

    $urlmax = $rowurlmax['guid'];

    //retrieve URL for second latest post

    $resulturlmiddle = mysql_query("SELECT

    i
    FROM
    _
    WHERE
    ='$middle'")

    or die(mysql_error());

    $rowurlmiddle = mysql_fetch_array($resulturlmiddle)

    or die("Invalid query: " . mysql_error());

    $urlmiddle = $rowurlmiddle['guid'];

    //retrieve URL for third latest post

    $resulturlmin = mysql_query("SELECT

    i
    FROM
    _
    WHERE
    ='$low'")

    or die(mysql_error());

    $rowurlmin = mysql_fetch_array($resulturlmin)

    or die("Invalid query: " . mysql_error());

    $urllow = $rowurlmin['guid'];

    //display the most recent post as hyperlink in the browser

    echo '<h3>Recent Blog Post</h3>';

    echo '

    ';

    ?>

    Posted 1 year ago #
  3. Wallpapers-Master
    Member

    @sayyam

    I can't see where you have the RSS feed to your wordpress in the home page.

    But it's not a security risk to have Database passwords !! Also what if i want to get RSS updates from any other site which i don't have the passwords for !

    Posted 1 year ago #
  4. yes
    i obsereved after dat
    anyhow the other tutorial do not have the database integration option

    Posted 1 year ago #

RSS feed for this topic

Reply

You must log in to post.