One thing you didn’t know about WordPress images.

By default in WordPress when you server up a .JPEG file, WordPress optimizes the image to save bandwidth and space. 90% of the time, no one will realize this as the WordPress function behind image optimization does a fantastic job at keeping it’s quality the same, unless you are using very large high quality photo .jpeg files.

By default WordPress uses a default quality of 90%, if you wish to revert the image quality throw the following function in your functions.php file:

add_filter( 'jpeg_quality', 'smashing_jpeg_quality' );
function smashing_jpeg_quality() {
return 100;
}

Personal inspiration for September

Just leaving this here for now…

Design is not just what it looks like and feels like. Design is how it works.

“Most people make the mistake of thinking design is what it looks like. People think it’s this veneer – that the designers are handed this box and told, ‘Make it look good!’ That’s not what we think design is. It’s not just what it looks like and feels like. Design is how it works.”

– Steve Jobs

Interacting with WP_Query, listing more posts from the current category.

For a new project of mine I was creating a single.php for the blog side of the website. The website had a few specific categories for the blog, these being News, Races and Events.

Whenever you were reading a blog post under one of these categories, the sidebar should show readers more posts from that specific category. May it be News, Races or Events. So we needed a way to show only the posts from the category that particular post was tagged under.

I decided that interacting with WP_Query here would be the best thing to do. The next thing we need to do is, because we are on a single.php page we need to find out what category that post is in. We can do this by using the get_the_category function.


// Assign get_the_category to a variable
$catData = get_the_category();

Here we have simply just stored the wordpress function get_the_category(); to a variable $catData. This is so we can use it later. The next step is to get the Category ID, in WordPress Categories are counted as Taxonomies and we can get the ID by passing the get_the_category(); variable through the term_id. Like so:


// Assign get_the_category to a variable
$catData = get_the_category();
$catID = $catData[0]->term_id;

As you can see we have a ‘[0]’ within our $catData. This is because get_the_category returns an array of objects due to a post potentially having numerous categories. By using ‘0’ our array will just loop through the first category. Now that we have found our current category, no matter what post single.php we are on, this will show us the category for this post, which is great if there are going to be more categories created down the line. This is a good way to future proof the website.

The final bit is putting this all together within the WP_Query. So let’s do that:


// Assign get_the_category to a variable
$catData = get_the_category();
$catID = $catData[0]->term_id;
$query = new WP_Query('cat'=.$catID);
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
echo '
<ul>
	<li>' . get_the_title() . '</li>
</ul>
&nbsp;

';
}
} else {
// no posts found
}

This will simply loop through all the posts found in the current category and output them in a list item showing the title.