wordpress

Access WordPress inbuilt filemanager for custom plugins


## HTML

<a href="#" class="custom_media_upload">Upload</a>
<img class="custom_media_image" src="" />
<input class="custom_media_url" type="text" name="attachment_url" value="">
<input class="custom_media_id" type="text" name="attachment_id" value="">

## PHP

if(function_exists( 'wp_enqueue_media' )){
wp_enqueue_media();
}

## JS

jQuery(document).ready(function($) {


var custom_uploader;
jQuery('.custom_media_upload').click(function(e) {

e.preventDefault();

custom_uploader = wp.media({
      title: 'Custom Title',
      button: {
      text: 'Custom Button Text'
  },
  multiple: true // Set this to true to allow multiple files to be selected
})
.on('select', function(el, bl) {

   var attachment = custom_uploader.state().get('selection').first().toJSON();
   console.log(custom_uploader.state());

   $('.custom_media_image').attr('src', attachment.url);
   $('.custom_media_url').val(attachment.url);
   $('.custom_media_id').val(attachment.id);
})
.open();
return false;
});
});
Advertisements
wordpress

Easy WordPress pagination without plugins


Easy WordPress pagination without plugins
Posted: 06 Apr 2012 03:52 AM PDT
Simply paste the following code where you want to display your pagination:

global $wp_query;
$total = $wp_query-&gt;max_num_pages;
// only bother with the rest if we have more than 1 page!
if ( $total &gt; 1 ) {
// get the current page
if ( !$current_page = get_query_var(‘paged’) )
$current_page = 1;
// structure of “format” depends on whether we’re using pretty permalinks
$format = empty( get_option(‘permalink_structure’) ) ? ‘&amp;page=%#%’ : ‘page/%#%/’;
echo paginate_links(array(
‘base’ =&gt; get_pagenum_link(1) . ‘%_%’,
‘format’ =&gt; $format,
‘current’ =&gt; $current_page,
‘total’ =&gt; $total,
‘mid_size’ =&gt; 4,
‘type’ =&gt; ‘list’
));
}
Thanks to Smashing Magazine for the cool tip!

CSS, CSS 3, wordpress

Zebra-striping the Comments


Zebra-striping the Comments

Zebra-striping, or highlighting every second element in a series, has traditionally involved selecting all the elements via javascript, then looping through them and highlighting all the odd elements. CSS 3 introduces the pseudo-class “nth-child”, which makes it ridiculously simple to do this without javascript. We’ll use it to zebra-stripe the comments.

  1. section#comments article:nth-child(2n+1) {
  2.     padding: 21px;
  3.     background: #E3E3E3;
  4.     border: 1px solid #d7d7d7;
  5.     /* Border-radius not implemented yet */
  6.     -moz-border-radius: 11px;
  7.     -webkit-border-radius: 11px;
  8. }

The weird value “2n+1″ is actually pretty simple if you understand what it stands for:

  • 2n selects every second item. If you wrote 3n it would select every third item, 4n every fourth item, and so on.
  • The +1 tells the browser to start at element 1. If you are familiar with programming you probably know that all arrays start at 0, and this is also true here. This means that element 1 is actually the second element in the series.

Alternatively, you could simply write:

  1. section#comments article:nth-child(odd) { … }

Since the standard includes the two most used values as shorthand, odd and even. The rest of the comment styling should be simple to understand with your new knowledge.

article reference : http://neolinx.com.np/blog/

wordpress

wordpress Subscribe plugin


http://wordpress.org/extend/plugins/subscribe2/

 

Subscribe2 provides a comprehensive subscription management and email notification system for WordPress blogs that sends email notifications to a list of subscribers when you publish new content to your blog.

Email Notifications can be sent on a per-post basis or periodically in a Digest email. Additionally, certain categories can be excluded from inclusion in the notification and posts can be excluded on an individual basis by setting a custom field.

The plugin also handles subscription requests allowing users to publicly subscribe (Public Subscribers) by submitting their email address in an easy to use form or to register with your blog (Registered Users) which enables greater flexibility over the email content for per-post notifications for the subscriber. Admins are given control over the presentation of the email notifications, can bulk manage subscriptions for users and manually send email notices to subscribers.

The format of the email can also be customised for per-post notifications, subscribe2 can generate emails for each of the following formats:

  • plaintext excerpt
  • plaintext full post (Registered Users only)
  • HTML excerpt (Registered Users only)
  • HTML full post (Registered Users only)

If you want to send full content HTML emails to Public Subscribers too then upgrade to Subscribe2 HTML.

  1. subscribe2 screenshot 1The Posts->Mail Subscribers admin page generated by the plugin.
  2. subscribe2 screenshot 2The Tools->Subscribers admin page generated by the plugin.
  3. subscribe2 screenshot 3The Users->Subscriptions admin page generated by the plugin.
  4. subscribe2 screenshot 4The Options->Subscribe2 admin page generated by the
wordpress

Use Hooks And Cron To Schedule Events


Use Hooks And Cron To Schedule Events

Sm9 in 10 Useful WordPress Hook Hacks

The problem.
You probably already know that WordPress can schedule events. For example, it can publish posts at preset dates and times. Using hooks and wp-cron, we can easily schedule our own events. In this example, we will get our WordPress blog to send us an email once hourly.

The solution.
Paste the following code block in the functions.php file of your theme.

1 if (!wp_next_scheduled('my_task_hook')) {
2     wp_schedule_event( time(), 'hourly''my_task_hook' );
3 }
4
5 add_action( 'my_task_hook''my_task_function' );
6
7 function my_task_function() {
8     wp_mail('you@yoursite.com''Automatic email''Hello, this is an automatically scheduled email from WordPress.');
9 }

Code explanation.
The first thing we did, of course, was create a function that performs the desired action. In this example, the function is called my_task_function() and it just sends an email to the specified email address.

To schedule an event, we have to use the wp_schedule_event() function. The last argument has to be a hook, which is why we hook our my_task_function() function to my_task_hook.

Sources:

 

wordpress

Prevent Duplicate Content On Comment Pages


 Prevent Duplicate Content On Comment Pages

Sm7 in 10 Useful WordPress Hook Hacks

The problem.
Duplicate content is an SEO problem for many websites. It can also be a problem for your WordPress blog if you don’t apply a few tricks.

Introduced in version 2.7, paged comments is a great addition to WordPress because it lets bloggers split comments into multiple pages. The only problem, again, is the risk of duplicate content.

Let’s use the new rel="canonical" attribute to prevent duplicate content in paged comments.

The solution.
Simply paste the following code in your function.php file:

01 function canonical_for_comments() {
02     global $cpage$post;
03     if $cpage > 1 ) :
04         echo "\n";
05         echo "<link rel='canonical' href='";
06         echo get_permalink( $post->ID );
07         echo "' />\n";
08      endif;
09 }
10
11 add_action( 'wp_head''canonical_for_comments' );

Code explanation.
First, we create a function to add the rel="canonical" attribute to comment pages, except page 1. Then we hook this function to WordPress’ wp_head() function. As simple as that!

Sources: