Explore » Food & Cooking » | Shopping » | Health & Fitness » | Beauty »

Posts Tagged “code hack”

“How to Change Default Full Size Image for Wordpress”

Tuesday, February 24th, 2009

Just thought I’d share something I just figured out:

I am now posting images that are 700 px wide. Sometimes, bigger is better.

However, even if I specify the image to be inserted at full size, Wordpress still shrinks it to 500 px wide.

I was able to fix that by editing wp-includes/media.php on line 34.  Just look for where it says 500 and change to whatever you want.

It also seems that it’s coded to first check to see what your content_width setting is, but I don’t know where that is set and right now I’m too tired and lazy to look for it.  Specifying your content_width, however, would be the best thing to do so that your images will adjust to fit whatever theme you’re using (I’m assuming that variable is set somewhere in a theme’s files).  I will add this to my mental to-do list for later.

“Guide to NextGEN Gallery Plugin: Album and Gallery”

Sunday, November 23rd, 2008

Please note: The following was written for NextGen version 0.99.1 and Wordpress 2.6.3. Depending on your version of NextGen and/or Wordpress, there may be slight to significant variances.

I have noticed that there’s a lack of clear documentation for the NextGEN photo gallery plugin for Wordpress.  The programmer doesn’t have time to write anything clear in English, especially when English is not his native language.

After seeing a lot of hits to this site for my earlier post about a NextGEN random image tweak, I figured it would be helpful to write a quick guide about how to set up a Photo Album page and add galleries and photos using the NextGEN plugin.

First, you have to download, extract and upload the NextGEN files to your Wordpress plugins directory.  Second, activate this plugin.

Now, in order to use the plugin, you need to understand how it is organized.  In NextGEN, an “album” is a container for a “gallery.”  An album can contain one or more galleries.

A gallery is a container for your photos.  For most people, you would only need to create one album.  You’ll probably create a lot of different galleries and put it in that album.  Maybe if you have a site that has different sections or authors, you might create multiple albums such as “Kelly’s Photos,” “Mike’s Photos,” “Holly’s Photos,” etc., but for most people, one album is enough.

So after activating your plugin, you’ll want to create your album.  You should have a new option in your main admin menu (after Write, Manage, Design, Comments, etc.) called Gallery.  This is where you go to set up and manage your NextGEN plugin.

Go there, click on “Album” and add a new album.  Click update.  If this is the first album you’ve created, your album ID is 1.  If not, you can get your album ID by selecting it from the dropdown.  The page will update to show your album ID.

Now, create a new Wordpress page that will display this album.  Call this page something like “Photos” or “Album.”  Depending on your Wordpress theme, it should show up in your navigation or where ever your page listings show up.  I called mine “Photo Gallery” though this is the opposite of how NextGEN is organized (in my head, a gallery should be a collection of albums, but NextGEN has it the other way around with an album being a collection of galleries, anyway…)

In the HTML editor for this new page put [album=#,compact] OR [album=#,extended].  Of course, replace # with the actual number that corresponds to your album ID.  The difference between the compact style or the extended style can be seen here. Ignore the code they give you on that page; it seems to be for an earlier version of the plugin.  My main photos page uses the compact style.

Once you have created this Album page, it’s time to put some photo sets, aka galleries, into it.  Go back to the NextGEN administration menu and click on “Add Gallery.”  Give a name for your gallery and click Add gallery.  The name doesn’t have to be anything fancy because you can control the actual name people will see later. You can’t put any space in the name, but if you do they will be turned into hyphens.

After you’ve added the gallery, you get 3 options on how to add pictures to the gallery.  The “Upload a Zip-File” option has been buggy for me, and the “Upload Images” option takes too long.  What I like to do is upload the photos I want using FTP.  After you gave the gallery a name, a new folder was automatically created for it on your server.  Connect using your FTP program and upload your photos into wp-content/gallery/your-new-gallery-name/ (ignore the thumbs folder). Then click the “Import Image Folder” option in the NextGEN administration.  Make sure to update the page with the name of your new gallery followed by a trailing forward slash (/) so it looks like wp-content/gallery/your-new-gallery-name/ and you can leave the box checked or unchecked depending on whether or not you want to import the details about when the photo was taken, lighting conditions, camera model, etc.

Once you’ve imported your photos, click on “Manage Gallery.”   Under the Action column, click on “Edit” for the gallery you just created.  Here, you can give a name and description for your gallery.  The name is what your site visitors will see, and if you had chosen the extended style, they will also see the description.

Then for the “Create New Page” dropdown select the name of your Wordpress Album page that you created earlier and click on “Add page.”  What this will do is automatically create a child page under your Album page containing this gallery.  If for some reason you don’t want this gallery to be a child of your Album page, you can create it as a child of any of your other existing pages or have it be a main page on its own.

Once you click “Add page,” the “Page Link to” will automatically update.  The other thing you want to do here is select a “Preview image” which will be your gallery cover.  Don’t forget to click “Save Changes” if you do so.

Optionally, you can give each photo a description (will show up as a “caption” for each photo), title and alt text, and tags.  Again, don’t forget to click “Save Changes.”

The final step is to have this new gallery you just created, full with photos, to show up on your Wordpress Album page (you may not always want this if you want to keep this gallery hidden or have it manually show up somewhere else).  In the NextGEN administration area, click on “Album” and select your album from the dropdown.  Once you do so, you can drag and drop your gallery from the right into the album on the left.   Click “Update” once you are done.  Now this gallery will show up on your Album page.  Visit your Wordpress Album page to see the changes.

If you want to display a gallery within a post, simply get the gallery ID of that gallery (visible on the Manage Gallery page in the administration area) and add the code

to the HTML editor of the post.  For example, you can create a gallery of photos from a party, optionally have it show up on your Album page or not, and then write a post about the party and embed the gallery right in that post with the code.

Coming soon, I’ll write something about displaying a small gallery of random or recent photos from our NextGEN in your sidebar or anywhere else in your Wordpress theme.

Here’s a diagram of the basic NextGEN structure:

NextGEN Plugin Structure

“NextGen Gallery: Random Photos from a Specific Gallery”

Sunday, November 16th, 2008

Please note: The following was written for NextGen version 0.99.1 and Wordpress 2.6.3. Depending on your version of NextGen and/or Wordpress, there may be slight to significant variances and this issue may have been fixed in newer releases.

This is a detailed discussion of why the original manual function call doesn’t work (widget works) and how I ended up fixing it. Click the following link if you want to skip all the explanation: how to manually display a random or recent photo from a specific NextGen gallery in your Wordpress template. If you need the basics on getting NextGEN to work and show your photos, click here for a quick guide to common NextGEN codes.

###

I really like the NextGEN photo gallery plugin for Wordpress, despite its lack of documentation and some confusing organization.

For example, in NextGEN you create what they call an “album,” which is a collection of one or more galleries. Galleries contain your photos. To me, it makes more sense to call the first part the “gallery” and your collection of photos should be called “albums,” but they have it backwards. I also don’t see a reason why you would need to create more than one NextGEN album. I think the confusion arises because English is not the programmer’s first language, but with that aside, it is still the best photo gallery plugin I’ve come across for Wordpress.

This post is about how to pull a random image from a specific category. It’s something I wanted to do tonight on my About page and I didn’t see anything about it on NextGEN’s official website or on Google. However, my numerous Google searched revealed that a lot of people have been trying to do the same thing, looking for help on forums and in Wordpress with no luck. I decided to give it a crack and was successful after some trial and error. So for others who may be in the same boat as I was, here’s how to display a random photo from a specific gallery in NextGEN anywhere in your template. This can be adapted to pull recent photos also.

In case you don’t know, you can show random or recent photos using the NextGEN widget. My theme doesn’t use Wordpress widgets, so in my sidebar is the manual code that the programmer provided. The code for random images is:

<?php
if (function_exists("nggDisplayRandomImages"))
{ nggDisplayRandomImages($number_of_pic,$Width,$Height); }
?>

It can be simplified to:

<?php nggDisplayRandomImages($number_of_pic,$Width,$Height); ?>

In my sidebar, I have 6 thumbnails that are 50 x 50, so my sidebar code is:

<?php nggDisplayRandomImages(6,50,50); ?>

This was my starting point. I figured if the widget allowed you to restrict the photos to a specific gallery, the manual code should do the same. I opened up the nggwidget.php file (found in /wp-content/plugins/nextgen-gallery/) and looked at the code. I did a search for the function being called: nggDisplayRandomImages. It’s near the bottom of the page and I saw that the function had several settings:

function nggDisplayRandomImages($number, $width = "75", $height = "50", $exclude = "all", $list = "")
{

	             $options[1] = array('title'=>'',
						'items'=>$number,
						'show'=>'thumbnail' ,
						'type'=>'random',
						'width'=>$width,
						'height'=>$height,
						'exclude'=>'all',
						'list'=>$list   );

	nggWidget::ngg_widget_output($args = array(), 1, $options);
}

What this means is that when you put the code in your template, in the parentheses you can set 5 options. The order is very important.

nggDisplayRandomImages($number, $width, $height, $exclude, $list)

$number: the number of pics you want to display, there is no default, so you have to provide this
$width: the width of each picture, defaults to 75 if you don’t provide anything
$height: the height of each picture, defaults to 50 if you don’t provide anything
$exclude: gallery restriction type
all means include all galleries
denied means deny the galleries in $list
allow means only allow the galleries in $list
In the code, it defaults to all but this means nothing because it is hard-coded to submit “all” in the array
$list: gallery IDs affected by your $exclude, defaults to blank but it doesn’t matter since $exclude is hard-coded

These are other settings that you can’t seem to set when you call the function but is hard-coded and sent in the array:
’show’ => ‘thumbnail’
This is the image file being shown, either the thumbnail or the original image
‘type’ => ‘random’
Either random or recent pictures

Because the exclude is hard-coded, it won’t work if you were to try and do:

<?php nggDisplayRandomImages(1,50,50,allow,3); ?>

That above code is trying to say show 1 random image, 50px by 50px, and only allow an image from the gallery with an ID of 3. But since $exclude has been hard-coded in nggwidget.php to “all” the function ends up still choosing from all galleries.

So the function needs to be changed, but because I use the function as-is for my sidebar, changing it would affect my sidebar display. What to do? Copy, paste, and modify.

In nggwidget.php:

I copied the entire nggDisplayRandomImages function and made certain changes to suit my needs:

function nggDisplayRandomImage_Vuthy
($number = "1", $width = "300", $height = "300", $exclude = "allow", $list = "1")
{

	$options[2] = array('title'=>'',
						'items'=>$number,
						'show'=>'orginal' ,
						'type'=>'random',
						'width'=>$width,
						'height'=>$height,
						'exclude'=>$exclude,
						'list'=>$list   );

	nggWidget::ngg_widget_output($args = array(), 2, $options);
}

As you can see, I gave it a new name so when I want to display it in my template, I’m using the following code:

<?php nggDisplayRandomImage_Vuthy(); ?>

Since I’m only going to use this for one particular thing, I set a few defaults so I don’t have to enter it into the function call in my template. I removed the hard-coded items from the array so it sends either my defaults or what I specific in the function call in my template. Plus I changed the show type to ‘orginal’ because I’m displaying a 300 x 300 image and would rather have it shrink my full-size image file than stretch out my thumbnail file. And yes, the programmer spelled original wrong; the correct spelling won’t work. You can also set it up so you can specify the setting for ’show’ each time you call the function, but it wasn’t necessary for my needs.

I’ll be the first to admit that I just a hack. I learn by trial and error, changing something and seeing what was affected. Don’t fully understand all this PHP, but this works and that’s good enough for me. :)

Update: I wrote a guide to creating albums and galleries in NextGEN.

Categories

EventCalendar:

March 2010
Sun Mon Tue Wed Thu Fri Sat
 123456
78910111213
14151617181920
21222324252627
28293031EC
    • No events.
Dugg:

Clicky Web Analytics