Archive for the ‘Web Design’ Category

Refreshing CSS on Facebook Pages

Posted on: 11th April 2011 No Comments

I was writing HTML in the static FBML app for a Facebook Page, when the changes I made to my CSS-file didn’t show up on the actual page. After double checking that it wasn’t the CSS that was screwed, I discovered that Facebook stores the imported CSS in a cache, so that it doesn’t have to send an external request every time someone looks at the page. That is probably a very good thing to do, but how could I tell Facebook that I had made changes to the CSS, without renaming the file every time?

Well the solution wasn’t that far off. When you use an external CSS-file, you use a standard link-tag like this:

<link rel="stylesheet" type="text/css" href="http://domain.com/css/facebook.css" />

What you need to do is add a version variable to the tag, like this:

<link rel="stylesheet" type="text/css"
href="http://www.domain.com/css/facebook.css?v=1.1" />

So every time you make CSS-changes, you have to edit the link tag in the static FBML app with a new version (1.2, 1.3 and so on), telling Facebook it is time to have a look at the file with fresh eyes.

I learn something new every day.

 

How to display wordpress posts on another page

Posted on: 10th November 2010 No Comments

On my Bond page, I have installed WordPress as a blogging tool in the folder nullnullsju.net/blogg. But I wanted to display the last blogposts on the main frontpage. So how to display WordPress post outside the main blog folder?

To display the post on other pages, you need to first load WordPress’ wp-load.php file into the page in question. And the PHP code is as follow:

<?php
define('WP_USE_THEMES', false);
require('./blogg/wp-load.php');
query_posts('showposts=2');
?>

To explain the lines. The first tells WordPress it shouldn’t use WordPress’ theme. The second imports the file. You obviously need to change this to reflect your installation. And the last line tells WordPress how many posts to display. In this case, it shows two posts.

If you want to display the posts on another site, change the require line to include the whole URL.

So now you have loaded the posts, and now you have to display them. And you can do that by a code similar to this:

<?php while (have_posts()): the_post(); ?>
 <h1><?php the_title(); ?></h1>
 <a href="<?php the_permalink(); ?>">
 <?php the_excerpt(); ?>
 </a>
 <?php endwhile; ?>

You can of course format this as you want. To explain the code:
The first line starts the loop that displays the posts.
The second line displays the post title (in H1 tags).
The third line starts the link with the post’s permalink.
The forth line prints the excerpt (who then becomes the link). The link is closed in the fifth line, and the loop is closed in the last line.

If you want to display the content of the post, you use the_content() in the code.