Aeonexe
5/25/2018 - 2:08 PM

VS Code php Snippets

Visual Studio code snippets

{
	// Place your snippets for php here. Each snippet is defined under a snippet name and has a prefix, body and 
	// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
	// same ids are connected.
	// Example:
	// "Print to console": {
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
	"Comments": {
		"prefix": "comment",
		"body": [
			"/*",
			" * $1",
			" */",
			"",
			"$2",
		],
		"description": "Bloque de comentario php"
	},
	"Comments 2": {
		"prefix": "comment 2",
		"body": [
			"/**",
			" * $1",
			" */",
			"",
			"$2",
		],
		"description": "Bloque de comentario php alternativo"
	},
	"Comments alt": {
		"prefix": "comment extended",
		"body": [
			"/*********************************************************************************",
			" * $1",
			" */",
			"",
			"$2",
		],
		"description": "Bloque de comentario php"
	},
	"PHP open tag": {
		"prefix": "<?php ?>",
		"body": [
			"<?php $1 ?>"
		],
		"description": "Habre php"
	},
	"PHP open short tag alt": {
		"prefix": "<?php alt ?>",
		"body": [
			"<?= $1 ?>"
		],
		"description": "Habre php corto"
	},

	"wp loop": {
		"prefix": "<?php wp loop",
		"body": [
			"<?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>",
			"",
			"	$1",
			"",
			"<?php endwhile; else : echo \"Aún no se ha publicado nada\"; endif; ?>"
		],
		"description": "Wordpress Loop"
	},
	"Loop": {
		"prefix": "wp_loop",
		"body": [
			"if( have_posts() ) { while( have_posts() ) { the_post();",
			"",
			"	$1",
			"",
			"} } else { echo \"Aún no se ha publicado nada\";  }"
		],
		"description": "Wordpress Loop"
	},
	"ACF rows contained": {
		"prefix": "<?php if have_rows",
		"body": [
			"<?php if( have_rows( '$1' ) ) : while( have_rows( '$1' ) ) : the_row(); ?>",
			"",
			"	$2",
			"",
			"<?php endwhile; endif; ?>"
		],
		"description": "ACF Rows"
	},
	"ACF rows": {
		"prefix": "if have_rows",
		"body": [
			"if( have_rows( '$1' ) ) { ",
			"",
			"	while( have_rows( '$1' ) ) {",
			"",
			"		the_row();";
			"",
			"		the_sub_field( '$2' );",
			"",
			"	}",
			"}",
			"$3";
		],
		"description": "ACF Rows"
	},

	// Subfield
	"ACF Sub field": {
		"prefix": "the_sub_field",
		"body": [
			"the_sub_field( '$1' );",
		],
		"description": "ACF Subfield"
	},
	"ACF Get Sub field": {
		"prefix": "get_sub_field",
		"body": [
			"get_sub_field( '$1' );",
		],
		"description": "ACF get Subfield"
	},

	"ACF if Get Sub field php tags": {
		"prefix": "<?php if get_sub_field",
		"body": [
			"<?php if( get_sub_field( '$1' ) ) : ?>",
			"	<?php the_sub_field( '$1' ); ?>",
			"<?php endif; ?>",
		],
		"description": "ACF get Subfield"
	},

	"ACF if Get Sub field": {
		"prefix": "if get_sub_field",
		"body": [
			"if( get_sub_field( '$1' ) ) {",
			"";
			"	the_sub_field( '$1' );",
			"";
			"}",
		],
		"description": "ACF get Subfield"
	},

	"ACF Sub field Option": {
		"prefix": "the_sub_field option",
		"body": [
			"the_sub_field( '$1', 'option' );",
		],
		"description": "ACF Subfield Option"
	},
	"ACF Get Sub field Option": {
		"prefix": "get_sub_field option",
		"body": [
			"get_sub_field( '$1', 'option' );",
		],
		"description": "ACF get Subfield Option"
	},

	"ACF if Get Sub field Option": {
		"prefix": "<?php if get_sub_field option",
		"body": [
			"<?php if( get_sub_field( '$1', 'option' ) ) : ?>",
			"	<?php the_sub_field( '$2', 'option' ); ?>",
			"<?php endif : ?>",
		],
		"description": "ACF get Subfield Option"
	},

	// Field
	"ACF Field": {
		"prefix": "the_field",
		"body": [
			"the_field( '$1' );",
		],
		"description": "ACF Field"
	},
	"ACF Get Field": {
		"prefix": "get_field",
		"body": [
			"get_field( '$1' );",
		],
		"description": "ACF get Field"
	},
	"ACF if Get Field php tags": {
		"prefix": "<?php if get_field",
		"body": [
			"<?php if( get_field( '$1' ) ) : ?>",
			"	<?php the_field( '$1' ); ?>",
			"<?php endif; ?>",
		],
		"description": "ACF get Field"
	},
	"ACF if Get Field": {
		"prefix": "if get_field",
		"body": [
			"if( get_field( '$1' ) ) {",
			"	the_field( '$1' );",
			"}",
		],
		"description": "ACF get Field"
	},

	// Field option
	"ACF Field Option": {
		"prefix": "the_field option",
		"body": [
			"the_field( '$1', 'option' ); ?>",
		],
		"description": "ACF Field Option"
	},
	"ACF Get Field Option": {
		"prefix": "get_field option",
		"body": [
			"get_field( '$1', 'option' ); ?>",
		],
		"description": "ACF get Field Option"
	},
	"ACF if Get Field Option": {
		"prefix": "<?php if get_field option",
		"body": [
			"<?php if( get_field( '$1', 'option' ) ) : ?>",
			"	<?php the_field( '$2', 'option' ); ?>",
			"<?php endif; ?>",
		],
		"description": "ACF get Field Option"
	},

	// field category
	"ACF Field term": {
		"prefix": "the_field category",
		"body": [
			"the_field( '$1', 'category_' . \\$category->cat_ID );",
		],
		"description": "ACF Field category"
	},
	"ACF Get Field term": {
		"prefix": "get_field category",
		"body": [
			"get_field( '$1', 'category_' . $category->cat_ID );",
		],
		"description": "ACF get Field category"
	},

	"WP Query": {
		"prefix": "<?php wp_query",
		"body": [
			"<?php ",
			"",
			"	\\$args = array(",
			"		'post_type'		=>	'$1',",
			"	);",
			"",
			"	\\$wp_query = new WP_Query( \\$args );"
			"",
			"?>",
			"",
			"<?php if( \\$wp_query->have_posts() ) : while( \\$wp_query->have_posts() ) : \\$wp_query->the_post(); ?>",
			"",
			"	$2",
			"",
			"<?php endwhile; endif; ?>"
		],
		"description": "The WP Query"
	},
}