ЧП Куликов Михаил Михайлович



Мы в социальных сетях...

    -  Вконтакте
    -  Facebook
    -  Google+
    -  Twitter
    -  LiveJournal
    -  Я.ру
    -  Одноклассники
    -  RSS
    -  Мой Круг
    -  YouTube


Анализ: траст сайта
Внимание!!! Заработал на 100% новый сервис.

Display WordPress content ouside of your blog

Оригинал статьи:

WordPress is a very powerful and flexible content management system (CMS) for blogs, and is among the first choices for anyone looking for a way to include dynamic content on their web sites. When using WordPress to power a news or blog section of an existing web site, authors will often want to display a list of headlines or the latest post on the front page of the site, outside of the WordPress-powered section. Using a bit of PHP and the WordPress API, this is easy to do.

This article assumes a basic familiarity with modifying WordPress templates, particularly the “loop” API.


In this, as well as all my tutorials, I use the domain name to refer to your domain. When you see this, substitute your actual domain name. As well, in this article I will assume you have installed WordPress into a directory called /wordpress. If you use a different name for your WordPress folder, just replace “wordpress” in any paths below with whatever name you chose.

The key to gaining access to the power of WordPress from an outside page lies in the wp-load.php file. This file loads the WordPress application and makes its API, and therefore your content, available for use. Once this file is included in a page on your site, you will be able to use any WordPress function just as if you were working in a WordPress template.

Let’s add the latest post to the front page of our site. We’ve already got a blog at but it would be nice to show the latest entry alongside the rest of the information on the front page. If your front page is already a PHP file, you’re ready to go; otherwise you’ll probably need to rename your front page file extension from .html to .php. (Be sure to test to ensure that doesn't break anything!)

The first thing we’ll do is pull in that all-powerful WordPress file, which we can do by adding this section to the very top of the page you want your post to appear on:

 <?php // Include WordPress define('WP_USE_THEMES', false); require('./wordpress/wp-load.php'); query_posts('showposts=1'); ?> 

The first line of this block is simply a comment describing what we’re doing. The second line tells WordPress not to display your templates, and the third line grabs that file I told you about. The final line performs a database query to retrieve the content we want to display on this page. In this example, we want the single most recent post, but the query_posts() documentation shows how to retrieve a variety of data.

Now we’ll move down in our page and find a good spot for this post. Once you’ve figure out where to put it, we’ll add a WordPress loop which will display the single post retrieved above:

 <?php while (have_posts()): the_post(); ?> <?php endwhile; ?> 

Once the loop is in place, we just have to decide what parts of the post to display, and write some HTML for them. Let’s say we want the post title and just an excerpt, followed by a link to the full article. We'd do something like this:

 <?php while (have_posts()): the_post(); ?> <h2><?php the_title(); ?></h2> <?php the_excerpt(); ?> <p><a href="<?php the_permalink(); ?>">Read more...</a></p> <?php endwhile; ?> 

If you’ve been writing WordPress themes, you’ll immediately recognize the template tags used here. We’re using all the same functions for the title, excerpt, permalink, etc, that we do in a WordPress template. Including wp-load.php makes this all possible.


You can even use this code to display blog posts on a completely separate web site, as long as it’s on the same server and you have filesystem access to the WordPress directory on the original site. Simply modify the require() in the first block on this page to use the full path to your WordPress installation:

 <?php // Include WordPress define('WP_USE_THEMES', false); require('/var/www/'); query_posts('showposts=1'); ?> 

Note: PHP restrictions such as open_basedir may prevent this last example from working..

Комментарии к посту «Display WordPress content ouside of your blog»

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *


Этот сайт использует Akismet для борьбы со спамом. Узнайте как обрабатываются ваши данные комментариев.


Курсы валют:


1 USD = 28.571 28.169
1 EUR = 34.722 34.130
1 RUR = 00.400 00.360

Антивирусы в формате SaaS
Подписаться письмом


SP:   LF:   PP:  

ubuntu == © Куликов М.М. (2011)
Сертифицированный партнер Dr.Web Free secondary DNS uaRating Rambler's Top100 Рейтинг bigmir)net TOP 100 Яндекс цитирования Ranker Рейтинг сайта в веб-каталоге