Skip to main content

UPDATE: Bootstrap Carousel = WordPress Dynamic Content

This is an update to my original post How to make Bootstrap Carousel display WordPress Dynamic Content, so I’ll keep it short…

The Original Source Code


Note: Bootstrap developers have added the .carousel-indicators feature sometime after my original post. Below, you will see my solution for generating the “data-slide-to” values dynamically…

Now with WordPress template PHP for dynamic content


Of course you’re free to pass all sorts of arguments within the query_posts('/*your_arguments*/');. I’ve left out “posts_per_page” this time, allowing the default to be whatever you have for Dashboard Settings > Reading > Blog pages show at most = “?” posts.
Note: I’ve removed .active from the .carousel-indicators li, as well as from the .carousel-inner .item. We’ll add it back with jQuery…

Add “active” Class to first items

$(“.carousel-indicators li:first”).addClass(“active”);
$(“.carousel-inner .item:first”).addClass(“active”);
The script must be called after the bootstrap js file, and preferably this is all happening in the footer.

Insert a Paged Blog Loop anywhere in your WordPress theme

$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query(‘post_type=post&posts_per_page=5′.’&paged=’.$paged); ?>

have_posts()) : $wp_query->the_post();?>

Note that the <?php bootstrap_pagination();?> function has already been discussed in our post “Add Twitter Bootstrap Pagination to your WordPress Theme“.

I won’t spend too much time explaining this one. Just know that this will start an independent loop of your choice anywhere you want in your theme templates. And it correctly incorporates wp’s pagination feature, which can be tricky. I primarily use this code in a template I call blog.php. Many clients want either a static home page, or magazine-style home page, but still want a blog-reel displayed elsewhere (a la the common index.php). My blog.php template featuring the above code can be easily added to any internal page of their choice. Of course, there are countless ways to customize the query parameters.

What Happend to WordPress’ Media File URL Option?

Beats me! God only knows why the wp folk decided to hose that option, or maybe it’s a bug. Whatever the case my be, I thought the custom File URL option (found under Settings > Media) was a very handy tool of which I have always made good use, and I want it back real bad. So bad, in fact, I figured out how. Very simply add this to your theme’s functions.php file:
update_option(‘upload_url_path’, ‘/wordpress/wp-content/uploads’);
Obviously, change the path to reflect your needs. Unfortunately, this hard-codes this path from functions.php, so although the field is added back to Settings > Media, and it may look like you can update the path from there, it will not save your changes. But in reality, a developer will only need to change this once or twice.

I find this option handy when developing a site at a temporary domain, knowing it will ultimately be migrated to a live domain. Otherwise, you get a fully-qualified temporary URL embedded in all your media attachments which are going to have to be changed anytime the site is moved to a new domain.
This option has saved me from the headache of having to mess with the wordpress mysql database more than necessary.

I will update this post as soon as I can add some convenience to this temporary solution.

Adding Custom Menu Locations in WordPress Themes

Basic Setup

Step 1: First, we need to register your new menus. In this example, we’ll create the menus Header Navigation and Expanded Footer. Add this PHP code to your functions.php, or link to it in a separate file:
// Add Your Menu Locations
function register_my_menus() {
‘header_navigation’ => __( ‘Header Navigation’ ),
‘expanded_footer’ => __( ‘Expanded Footer’ )
add_action( ‘init’, ‘register_my_menus’ );

Step 2: Let your users know that your menu location exists by adding a message to the front end when no menu is yet assigned. Insert this code directly below the previous:
function default_header_nav() { // HTML markup for a default message in menu location
echo “


function default_expanded_footer() {
echo “

Step 3: Insert this code into your templates wherever you want your Header Navigation menu to appear:
‘theme_location’ => ‘header_navigation’, // menu slug from step 1
‘container’ => false, // ‘div’ container will not be added
‘menu_class’ => ‘nav’, //

Display Posts from Current Month & Year in a WordPress Template

Hi Y’all,
I was presented with this challenge while putting together a magazine-type site, where the home page was to display articles from the current issue–meaning the current month and year. Checking the forums, I found some solutions, and although the topics have been closed, I have found that they are incomplete. Some call the current month, i.e. “March”, but don’t not discern the current year, showing posts from March 2013, March 2012, etc. And some simply don’t work at all, sorry to say.

Here’s what I came up with, and have proven to work…
$current_year = date(‘Y’, current_time(‘timestamp’));
$current_month = date(‘m’, current_time(‘timestamp’));
if(have_posts()) : while(have_posts()) : the_post();
<?php endwhile; endif; wp_reset_query(); ?>
Of course, there is room to pass way more arguments within query_posts(), but that’s the easy part.