WordPress is an Amazing tool, and it has 99% of what most people look for in a website. However, if you’re a Web Designer and design and code custom websites for your clients and don’t want to conform to the constraints of WordPress, BUT your clients still want to be able to update their own website, WordPress has a solution for you.
WordPress provides you with very powerful tools to embed its content into custom websites. So you built this gorgeous website frame with no content right? You install WordPress and add the content as either a post, or a page. Just throw one of the snippets below into your HTML, XHTML, HTML5 page where you want the WordPress content to appear:
Embed a WordPress Page:
|
|
<?php define('WP_USE_THEMES', false); require('blog/wp-blog-header.php'); $page_id = 4; $page_data = get_page($page_id); $content = apply_filters('the_content', $page_data->post_content); $title = $page_data->post_title; echo $title; echo $content; ?> |
The page ID is the ID generated by WordPress for that specific page, located in the Query String of the URL.
The
require('blog/wp-blog-header.php'); line refers to the location of the wp-blog-header.php file on your server.
Embed All The Posts
|
|
<?php define('WP_USE_THEMES', false); require('blog/wp-blog-header.php'); $posts = get_posts('numberposts=10&order=DESC&orderby=post_title'); foreach ($posts as $post) : start_wp(); ?> echo "<h3>" . the_title() . "</h3>"; echo the_content(); echo "<hr />"; endforeach; ?> |
Use the Query Parameters of the get_posts() functions provided by WordPress to narrow down the list of results returned.
You can also substitute get_posts() with query_posts() for a different set of results. For Example:
|
|
query_posts('showposts=3'); |
Which returns the last three posts.
Get Posts Published Between Two Dates
|
|
<?php function filter_where($where = '') { $where .= " AND post_date >= '2009-03-17' AND post_date <= '2009-05-03'"; return $where; } add_filter('posts_where', 'filter_where'); query_posts($query_string); while (have_posts()) : the_post(); the_content(); endwhile; ?> |
Insert Ads After the First Post
|
|
<?php if (have_posts()) : ?> <?php $count = 0; ?> <?php while (have_posts()) : the_post(); ?> <?php $count++; ?> <?php if ($count == 2) : ?> //Paste your ad code here <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <?php the_excerpt(); ?> <?php else : ?> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <?php the_excerpt(); ?> <?php endif; ?> <?php endwhile; ?> <?php endif; ?> |
Obviously replace //place your ad code here with your preferred advertisement code.
So now you can keep the amazing look you worked so hard on, and have your client be able to update his/her own content.