February 25, 200917 yr Hello!, I'm kinda new to the whole website thing, and i have recently made my first site for my own company www.ttpromotions.com Now if you look at the site on the first page, where all the main content is in that nice big white <div> on the first page. In there i want to add a blog, to keep my visitors up-to date with what we have been doing lately. I only want it there on the first page because, well it will save the hassle of converting the WHOLE site. Is it possible to do this ? would i be able to use an iframe ? Any input would be greatly appreciated.
February 25, 200917 yr Yes. Install WordPress on your server then add this PHP code at the very beginning of your XHTML document, before the doctype. <?php //db parameters . You can find this information in your wp-config.php file. $db_username = '###'; $db_password = '###'; $db_database = '###'; $blog_url = 'http://www.yourdomain.com/blog/'; //base folder for the blog //connect to the database mysql_connect(localhost, $db_username, $db_password); @mysql_select_db($db_database) or die("Unable to select database"); //get data from database $query = "Select * FROM wp_posts WHERE post_type='post' AND post_status='publish' ORDER BY id DESC LIMIT 1"; $query_result = mysql_query($query); $num = mysql_numrows($query_result); //close database connection mysql_close(); //assign data to variables $blog_date = mysql_result($query_result, 0, "post_date"); $blog_title = mysql_result($query_result, 0, "post_title"); $blog_content = mysql_result($query_result, 0, "post_content"); //$blog_permalink = mysql_result($query_result, 0, "guid"); //use this for 'p=11' format $blog_permalink = $blog_url . mysql_result($query_result, 0, "post_name"); //combine blog url, with permalink title. Use this for title format //format date $blog_date = strtotime($blog_date); $blog_date = strftime("%b %e", $blog_date); //how many characters should be shown? $maxchars = 135; //strip out the html tags, such as images, etc... $blog_content = strip_tags($blog_content); //cut down the size of the post to 135 characters $blog_content = substr($blog_content, 0, $maxchars); $blog_content = $blog_content . "..."; // html page starts after ?> ?> Add the following within the DIV to display the latest post content and title from your WordPress blog. < ?php echo $blog_title; ?> < ?php echo $blog_content; ?> Then just style as required. Hope this helps.
February 25, 200917 yr Author Holy S*** that was a fast response. Right i've installed wordpress to my server... Just give me a few mins and i will update you on my progress. Thankyou!
February 25, 200917 yr Author Right: Wordpress installed Code placed at the top of index.html Code placed in the div All it shows is the code literally in the div, take a look.. www.ttpromotions.com
February 25, 200917 yr Im not too sure, but i know that the page needs to be .php instead of .html. Change it quick because now anyone who see the source code can see the password for your database....
February 25, 200917 yr I think there is an easier way. Just create a new directory, lets say... /blog and install wordpress in that directory.
February 25, 200917 yr Author Haha, i realised that just before you posted and changed it quickly! But still no luck.. its still just showing the code underneath the introduction.
February 25, 200917 yr <?php echo $blog_title; ?> <?php echo $blog_content; ?> Sorry adjust the code to the above.
February 25, 200917 yr Author Thanks pedro but WDL's code seemed to do the trick. I have moved it into its own div class underneath the introduction. But if you have a look it is the same font as the introduction, how do i go about changing this ? thanks
February 25, 200917 yr OK. What you want to do is style it differently. In your CSS put the following: #blog_block p { font-family: change the font; color: change the colour; } Do you get what I mean? Hope this helps.
February 25, 200917 yr Author brilliant i've added it in and im on my way! Thank-you very much, you'd be surprised how much i just learnt from that! Unfortunately i have to go out now, but i will be updating it and cleaning it up when im back! Oh and i see your a web designer, i wonder if you could give me an constructive criticism on the site ? Thank-you again.
April 2, 200917 yr What does this mean? $query = "Select * FROM wp_posts WHERE post_type='post' AND post_status='publish' ORDER BY id DESC LIMIT 1"; Do I need to type something after the '=' ?
April 2, 200917 yr Nope. It's basically saying select the latest posts that have a status of published and order them by their ID but limit how many posts are displayed to 1.
Create an account or sign in to comment