Ever wanted to take a piece of
WordPress
functionality and put it in a non-WordPress portion of your website? Like,
for example, pulling your WordPress Sidebar and dropping it into a custom
page of yours?
Well, here’s how to make it work.
Many have tried doing this simple include below and have met with failure.
What they did was add the include by itself, like so:
wp_get_archives('type=monthly');
This ends in a fail whale because PHP doesn’t know what to do with that
request. Within a WordPress page it’s fine because you already have the
required headers loaded, but in your own custom web site they aren’t there.
So we’ll add them.
// turn off WordPress themes and include the WordPress core: define('WP_USE_THEMES', false); require($_SERVER['DOCUMENT_ROOT'] . '/wp-blog-header.php'); wp_get_archives('type=monthly'); ?>
If you include the WordPress blog header first (wp-blog-header.php) and
then invoke the piece of code you want, you’ll be able to add
WordPress functionality anywhere you want on your custom pages!
The code above (get_archives) allows me to display my entire blog archive on any page of mine I want —
even outside of a WordPress-generated page.
Get a weekly breakdown of what’s happening in security and tech—and why it matters.
This lets you get tons of functionality from WordPress, including:
Get a list of all your links
Pull your tag cloud from your posts
Pull your WordPress sidebar into a page
…and there are dozens more
here.
This is how I have created the page you’re reading this on. The entire page
is custom code; I only have a couple of pieces of WordPress embedded within
it —
the loop, and my archives toward the bottom on the right. This gives me the ability
to seamlessly blend my WordPress content with my custom content at
danielmiessler.com/study
and
danielmiessler.com/writing.
It’s the perfect combination — custom control + WordPress functionality.
Ping me at
daniel@danielmiessler.com
with any questions…
[
WordPress’s get_archives | wordpress.org
][
WordPress Template Tags | wordpress.org
][
The WordPress Loop | wordpress.org
][
The WordPress Codex | wordpress.org
]
Meet Mary — Your Smart AI ICT Teacher for O-Level Secondary Education in Uganda! Welcome…
Journey Through Faith: An Introduction to Senior Three Islamic Religious EducationWelcome, students, to an enriching…
Meet Isha Karungi — Your Smart AI Islamic Studies Teacher for O-Level! Welcome to the…
Having studied Spanish for over 6 years, I knew what dulce de leche meant. Sweet.…
I found kiwis on sale. Five for $1! In the middle of winter. In January.…
An experience. That’s what Ghirardelli is to me. For many years, San Francisco was a…
Leave a Comment