Add a custom footer menu in a WordPress Theme

* 1 Comment

Put this code in your functions.php

register_nav_menus(
  array('footer' => __( 'footer-menu', 'THEME_NAME' ),)
);

Then go into WordPress and add a new menu. Call it “footer”.

Then on the left side, you’ll now see a drop-down menu to set a footer menu. Select the “footer” menu you just created.

Finally, go to your footer.php file and call the menu using the following code:

<?php wp_nav_menu( array( 'theme_location' => 'footer' ) ); ?>

Add a NextGen Gallery in your theme

This is how to display a NextGen gallery in any page in your theme.

nggShowSlideshow(galleryID, width, height)

<?php echo nggShowSlideshow(2,700,228) ?>

Try it out!


Change the length of the WordPress Excerpt

Add this code in the “functions.php” file of your theme:

function new_excerpt_length($length) {
	return 23;
}
add_filter('excerpt_length', 'new_excerpt_length');

Fix NextGen Image Uploading issue in WordPress

I’ve been having this problem where my pictures won’t upload (or rather, show thumbnails) using the NextGen gallery in wordpress. Here’s how I solved it. Quite simple actually!

1. Change your php.ini memory_limit to 256M (mine was set on 64M)
2. Uncomment the following code in plugins/nextgen-gallery/lib/gd.thumbnail.inc.php

@ini_set('memory_limit', '256M');

Everything works now!


WordPress + Nextgen Gallery: Load Lightbox Gallery From One Image

* 24 Comments

This is an explanation of how to have multiple galleries on a page, yet only show one thumbnail, and that thumbnail shows all of the images in the gallery…in the lightbox view. Phew, it’s hard enough just to write out. But after trawling through the internet looking for the answer, I’ve jimmy-rigged it myself. I don’t know that I’d call it a hack…but at least your page load time isn’t affected. So here goes!

##UPDATE: I’ve just recorded a screencast for this tutorial, click here.

1. Install the NextGen Gallery plugin (I assume if you’re having the same problem I did!)
2. Create a new page, and call galleries into it like this:
[nggallery id=1 template=one]
[nggallery id=2 template=one]
[nggallery id=3 template=one]

3. Create a new subfolder in your theme folder called “nggallery”.
4. Create a blank php file in the subfolder called “gallery-one.php” (this is the template you called in step 2.
5. Read my explanations and then copy the code and see how it works for you.

(This first bit is copied from gallery.php in the NextGen plugin folder)

<?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?>
<?php if (!empty ($gallery)) : ?>

Next we have to set our iterator (to find out where we are in the loop…not The Loop though).

<?php $i=1; ?>

Then let’s put our holder (with the ID of the gallery appended in the class) that will wrap each gallery.

<div class="holder<?php echo $gallery->ID; ?>">

And then our foreach statement. Here you can see I’ve added an IF statement that says, “if this is the first image, then show me the thumbnail linked to the lightbox slideshow…otherwise just give me a link (no image, but you need the a tag), and set its display to none”. After that is done, but before the FOREACH statement is finished, make sure and increment our iterator with $i++;

<?php foreach ($images as $image) : ?>
	<?php if ($i < 2) : ?>
		< a href="<?php echo $image->imageURL ?>" <?php echo $image->thumbcode ?> title="<?php echo $gallery->title ?>">
			<img src="<?php echo $image->thumbnailURL ?>" /></ a>

<?php else : ?> < a style="display:none" href="<?php echo $image->imageURL ?>" <?php echo $image->thumbcode ?>>link</ a> <?php endif; $i++; ?> <?php endforeach; ?>

Finally, close out your wrapping div, and close out the IF statement from the top:

</div>
<?php endif; ?>

Here’s the full code

<?php
/**
Template Page for the gallery overview

Follow variables are useable :

	$gallery     : Contain all about the gallery
	$images      : Contain all images, path, title
	$pagination  : Contain the pagination content

 You can check the content when you insert the tag <?php var_dump($variable) ?>
 If you would like to show the timestamp of the image ,you can use <?php echo $exif['created_timestamp'] ?>
**/
?>
<?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?>
<?php if (!empty ($gallery)) : ?>

<?php $i=1; ?>

<div class="gallery-holder gal<?php echo $gallery->ID; ?>">
<?php foreach ($images as $image) : ?>

	<?php if ($i < 2) : ?>
		<div style="display:none;">
			<img src="<?php echo $image->imageURL ?>" />
		</div>
		<a href="<?php echo $image->imageURL ?>" <?php echo $image->thumbcode ?> title="<?php echo $gallery->title ?>">
			<img src="<?php echo $image->thumbnailURL ?>" /></a>
	<?php else : ?>
		<a style="display:none" href="<?php echo $image->imageURL ?>" <?php echo $image->thumbcode ?>>link</a>
<?php endif; $i++; ?>

<?php endforeach; ?>
</div>

<?php endif;?>

Create a “featured” blog in WordPress (with no duplicates)

In your category view in WordPress, wouldn’t it be awesome to show a ‘featured’ blog per category? Here’s how (after many hours of work!).

Step 1: Setup
First, make sure you have another category called “featured”. So when you want to create a featured blog entry in, say your category of “travel”, then you would select “travel” and “featured” as categories.

Step 2: Category.php
Now, go into category.php. From here, insert a bit of code just above The Loop. Here’s the explanation: We are going to create a query that pulls all blogs with the category ‘feature’, and then narrow it down by the current category, and then limit the items to 1. The default with wordpress is to sort things chronologically, so the most recent article you categorized as ‘featured’ and in the “travel” category, will show up.

Next, we will create a variable called “$do_not_duplicate”. This will store the ID of the post it pulls for the feature. It’s important to store this ID, because then we’ll want to make sure and skip over that ID when we pull the rest of our blogs up, so there are no duplicates.

Ok, here’s the code:

  <?php $my_query = new WP_Query('category_name=featured&cat='.$cat.'&posts_per_page=1');
   while ($my_query->have_posts()) : $my_query->the_post();
	$do_not_duplicate = $post->ID; 
	echo 'featured: ', the_title();		
   endwhile; ?>

Step 3: Start the Loop (minus the already featured article)
Replace the standard Loop starter with the following code:

  <?php if (have_posts()) : while (have_posts()) : the_post(); 
        if($post->ID == $do_not_duplicate) continue; ?>
    /* rest of loop content as normal */
<?php endwhile; endif; ?>

What this does is use that $do_not_duplicate variable from above, and just passes over it when you pull the rest of your blog entries in.

Hope it works for you!

If you need more help, try checking out how to do multiple loops on wordpress.org


Turning Off Comments for a Page in WordPress

* 1 Comment

Want to turn off (or on) comments for a page in wordpress. It’s actually quite easy…they just hid the option waaaaay up in the top corner of your screen. So edit your page, and then you go up to the top right and click “Screen Options”. When this little drop-down appears, make sure the option for “Discussion” is checked. Then scroll to the bottom of your page, and you’ll see an option for enabling/disabling comments and pingbacks.

Happy un-commenting!