Category 'Very Short Snippet'


WordPress folder functions: all paths lead to WordPress

WordPress offers many ways to access the names of folders and build new ones. Here's a useful list with examples performed, to be more clear, from a subfolder located in a hypothetical plugin:

Plugins

We begin with plugins_url() used to determine and build url when you write a plugin.

plugins_url ()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/ / If this line is performed by
/ / Http://www.miosito.com/wp-content/plugins/my_plugin/classes/test.php

plugins_url ( ) ; $ R = plugins_url ();
/ / Http://www.miosito.com/wp-content/plugins/

plugins_url ( 'myscript.js' , __FILE__ ) ; $ R = plugins_url ('MyScript.js', __ FILE__);
/ / Http://www.miosito.com/wp-content/plugins/my_plugin/classes/myscript.js

plugins_url ( 'assets' ) ; $ R = plugins_url ('assets');
/ / Http://www.miosito.com/wp-content/plugins/assets

trailingslashit ( plugins_url ( 'assets' ) ) ; $ R = trailingslashit (plugins_url ('assets'));
/ / Http://www.miosito.com/wp-content/plugins/assets/

More ...

WordPress: get_posts () and orderby

negli argomenti passati negli inputs. Through get_posts() you can select a sequence of exact post using the parameter post__in in arguments over the past inputs. . The order, however, is not consistent with the sequence indicated as WordPress performs checks on the clause ORDER BY in the select statement, even though version 2.8 is available from the value of none .

More ...

WordPress Snippet: extract meta get_posts value with ()

Working with a Custom Post Type ( CPT ) is natural to use the internal functions of WordPress to view and filter the posts of this type. , risulta comodissimo poter creare loop personali sulle proprie tipologie di post. Whether using the get_posts() is that you create an object directly WP_Query , it's very comfortable to create loops on their personal types of posts. WordPress also allows for filters for personal tassionomie, on the count, order, progressing to meta data. Useful, in fact, is the process that allows you to specify the conditions where that kind of meta data and compare it with rules.

More ...

WordPress Snippet: the action save_post

When adding fields to add pages and posts, or to get Custom Post Type ( CTP ), you have to record an action to save these new data. The implementation of this procedure is essentially always the same, changing only the fields and how to save, the extra data can reside in the 'custom field', or the table post meta, or on a personal or more tables.

More ...

WordPress Snippet: is_page () on Custom Post Type

If you recorded your own Custom Post Type ( CPT ), especially if you type 'page', you could serve to determine if you are viewing that particular page, the 'single' so to speak. . In this case it is useless to try is_page() or is_page_template() . The clean solution is as follows:

1
2
3
4
5
6
is_singular ( 'cpt_key' ) ) { if (is_singular ('cpt_key')) {
; global $ post;
$post -> post_name == 'slug_pagina' ) { if ($ post -> post_name == 'slug_pagina') {
/ / Your code here ... type add_action (), wp_enqueue_scripts (), etc ...
}
}

More ...

WordPress 3.3: jQuery all finally

With WordPress 3.3 also jQuery and all its modules have been aligned. Now it is possible to access the new list of modules in the latest release 3.3, such as the autocomplete. Here's a snippet for a good inclusion:

1
2
3
4
5
6
/ / Load modules that WordPress for us preparatory to the script "MyScript.js"
array ( 'jquery-ui-slider' , $ Deps = array ('jquery-ui-slider',
'Jquery-ui-datepicker',
'Jquery-ui-autocomplete'
);
, 'js/myscript.js' , $deps , 1 . 3 . 4 , true ) ; wp_enqueue_script ('key', 'js / MyScript.js', $ deps, 1. 3. 4, true);

More ...

WordPress Snippet: add styles and scripts to Custom Post Type

Now that WordPress allows you to create types of custom post (CPT), it becomes useful to be able to add our styles and our script when you view or edit our posts. The best way to do that is compatible with release 3.3 is the following:

1
2
3
4
5
6
7
, function ( ) { add_action ('admin_enqueue_scripts', function () {
; global $ typenow;
$typenow == 'id_custom_post' ) { if ($ typenow == 'id_custom_post') {
, 'css/customstyle.css' ) ; wp_enqueue_style ('key_style', 'css / customstyle.css');
, 'js/customscript.js' ) ; wp_enqueue_script ('key_script', 'js / customscript.js');
}
});

More ...

WordPress Snippet: src thumbnail

WordPress allows you to associate a thumbnail to a post , personalized page or post. , che restituiscono il completo tag img , risulta meno intuitivo come ottenere il solo link: If the entire image is easy to extract from the code, thanks to features the_post_thumbnail() or get_the_post_thumbnail , that return the full tag img , is less intuitive as to just the link:

1
2
3
4
/ / If $ post_id is the id of the post
get_post_thumbnail_id ( $post_id ) ; $ Image_id = get_post_thumbnail_id ($ post_id);
wp_get_attachment_image_src ( $image_id , 'full' ) ; $ Image = wp_get_attachment_image_src ($ image_id, 'full');
[ 0 ] echo $ image [0]

More ...

Sort an array of arrays in PHP

vista in WordPress: ordinare una serie di post per un campo qualsiasi può essere utilizzata facilmente anche per ordinare array di array . The PHP usort ( ) view Wordpress: order a series of posts for any field can be easily used to sort arrays of arrays. For example if we have:

1
2
3
4
5
6
7
8
9
array ( $ Args = array (
'nome' => 'mike' , 'anno' => 2001 ) , array ('name' => 'mike', 'year' => 2001),
'nome' => 'frank' , 'anno' => 2010 ) , array ('name' => 'frank', 'year' => 2010),
...
);

$args , function ( $a , $b ) { usort ($ args, function ($ a, $ b) {
$a [ 'anno' ] > $b [ 'anno' ] ) ; return ($ a ['year']> $ b ['year']);
});

More ...

Very short snippet: set the log file on WordPress

si attivano i log a video prodotti da PHP, riempiendo lo schermo di Notice, Warning e quant'altro. By setting the file wp-config.php define the define('WP_DEBUG', true); activates log in videos produced by PHP, filling the screen of Notice, Warning and whatnot. If checks for "flying" this may be useful in situations of exercise is not recommended, for obvious reasons. Luckily, WordPress allows her to "convey" such a log file, which by default is placed in /wp-content/debug.log .

More ...



Stop SOPA