Create Recent Post Shortcode

Here is an example of creating a shortcode with a parameter. I choose the recent post shortcode because it is the shortcode we usually use in the backend team

first thing is we have to code the post loop that will fetch all the post from the database, here is the simple example:

[php]

// Query
$the_query = new WP_Query( array ( ‘posts_per_page’ => -1 ) );

// Posts
echo ‘<ul>’;
while ( $the_query->have_posts() ) :
$the_query->the_post();
echo ‘<li>’ . get_the_title() . ‘</li>’;
endwhile;
echo ‘</ul>’;

// Reset post data
wp_reset_postdata();

[/php]

Now, since we are done in coding the structure of the loop we can now combine it to the shortcode. I put comments in the code to explain the use of each part

[php]
// Add Shortcode
function recent_posts_shortcode( $atts , $content = null ) {

// Attributes
$atts = shortcode_atts( // this variable is use to declare the shortcode parameters
array(
‘posts’ => ‘5’, //by adding the default value in the parameter the shortcode still become usable even if the user did not declare the number of post to show in the shortcode
),
$atts
);

// Query
$the_query = new WP_Query( array ( ‘posts_per_page’ => $atts[‘posts’] ) ); // as you notice the -1 is replace with $atts[‘posts’] which contain the default value

// Posts
$output = ‘<ul>’;
while ( $the_query->have_posts() ) :
$the_query->the_post();
$output .= ‘<li>’ . get_the_title() . ‘</li>’;
endwhile;
$output .= ‘</ul>’;

// Reset post data
wp_reset_postdata();

// Return code
return $output; //it will return all the contents.
}
add_shortcode( ‘recent-posts’, ‘recent_posts_shortcode’ );
[/php]

As you notice I use return instead of using echo in each content because base on my experience using echo in the shortcode may break the layout of the page where the shortcode is used.

For example I use
[php]
<div id="parentcontainer">
[recent-posts posts="2"]
</div>

//If I use echo in shortcode this is what I see sometimes in my DOM

<ul>
<li>Sample Title 1</li>
<li>Sample Title 2</li>
<li>Sample Title 3</li>
</ul>
<div id="parentcontainer">
</div>

//as you notice the result of the shortcode is go outside the parentcontainer..
[/php]

BTW..
We can now call the shortcode like this [recent-posts posts=”2″] or [recent-posts] and aside from posts parameter we can always add as many parameters as you want.

Wayback Machine Downloader

The Wayback Machine is the tool that allows users to use the Web archive to surf the web as it was. User are now be able to bring the old website back to live in an HTML version.

You can retrieve the website files using Wayback Machine Downloader. You can start to Scrap the site here and wait for the download link that will be sent to your email.

How to Apply Actions to a Bunch of Files?

Applying the same action manually to a bunch of files maybe time consuming for you and you may feel bored doing the same thing over and over among bunch of files.

But there is an easy way to do that mostly when you are resizing images with same proportions or applying a certain effect/layer style in a bunch of files.

By going to the Menu, File>Automate>Batch.

automate

By selecting Batch Files, you can apply the same action in a bunch of files inside a folder or can be opened files inside photoshop or inside the bridge.

Then it will autmomatically do the same action over and over among the files inside the specified location or folder.

2nd

After selecting the [Batch…] option, a pop up dialog will come to appear like the above shown in the image.

You can select the action you’ve created inside the Photoshop. Then you can specify the specific location/folder you want to apply the specified action then after setting some options, tadah! The Photoshop will automatically apply the specified action.

Adobe Photoshop: Layer Comps

Layer comps is one of the useful features of Adobe Photoshop. Layer comps can be very useful especially when you want to create different versions from a design save in a single file.

Sometimes we create different variation from the very first version of our design but with similarities so we tend to save those different designs inside a single file. We turn on/turn off layers to view those different layers back and forth that may consume time finding layers which are and which is to turn on/off.

Maybe you’re not aware of the function of Layer comps. It can be very helpful to you when doing such things.

layer-comps

Under the Window menu, you can find Layer comps. After selecting Layer comps, a pop up dialog will appear.

By clicking the ‘Create new layer comp’ icon at the bottom of the dialog, you can create Layer comp as many as you want. Turn on the layers you want to be visible, then select ‘Create new layer comp’.

You can rename that specific Layer comp in order to give sense what this Layer comp is. For example, version 1 or for example you are creating different color scheme, you can give a name related to that version, blue color scheme, red color scheme, etc.