Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Adding a small Blog to just one page of my site?

Featured Replies

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.

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.

  • 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!

  • 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

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....

I think there is an easier way.

Just create a new directory, lets say... /blog

and install wordpress in that directory.

  • 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.

<?php echo $blog_title; ?>   

<?php echo $blog_content; ?>

 

Sorry adjust the code to the above.

  • 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

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.

  • 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.

  • 1 month later...

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 '=' ?

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.

I'm getting an Unable to select database error - not sure why

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.