Last active
April 5, 2016 18:33
-
-
Save papplo/de4fa96536c760379f224a50798b7c01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Creating a function to create our CPT LENEROS | |
* | |
*/ | |
function create_posttype_leneros() { | |
register_post_type( 'leneros', | |
// CPT Options | |
array( | |
'labels' => array( | |
'name' => __( 'Leneros' ), | |
'singular_name' => __( 'Lenero' ) | |
), | |
'public' => true, | |
'has_archive' => true, | |
'rewrite' => array('slug' => 'leneros'), | |
) | |
); | |
} | |
// Hooking up our functions to theme setup | |
add_action( 'init', 'create_posttype_leneros' ); | |
/* | |
* Creating a function to create our CPT "Leneros" | |
* | |
*/ | |
function custom_post_type_leneros() { | |
// Set UI labels for Custom Post Type | |
$labels = array( | |
'name' => _x( 'Leneros', 'Post Type General Name', 'twentythirteen' ), | |
'singular_name' => _x( 'Leneros', 'Post Type Singular Name', 'twentythirteen' ), | |
'menu_name' => __( 'Leneros', 'twentythirteen' ), | |
'parent_item_colon' => __( 'Leneros', 'twentythirteen' ), | |
'all_items' => __( 'Todos los Leneros', 'twentythirteen' ), | |
'view_item' => __( 'Ver Leneros', 'twentythirteen' ), | |
'add_new_item' => __( 'Agregar nuevo Lenero', 'twentythirteen' ), | |
'add_new' => __( 'Agregar nuevo', 'twentythirteen' ), | |
'edit_item' => __( 'Editar Lenero', 'twentythirteen' ), | |
'update_item' => __( 'Actualizar Leneros', 'twentythirteen' ), | |
'search_items' => __( 'Buscar Leneros', 'twentythirteen' ), | |
'not_found' => __( 'Not Found', 'twentythirteen' ), | |
'not_found_in_trash' => __( 'Not found in Trash', 'twentythirteen' ), | |
); | |
// Set other options for Custom Post Type | |
$args = array( | |
'label' => __( 'Leneros', 'twentythirteen' ), | |
'description' => __( 'Grid en hompage', 'twentythirteen' ), | |
'labels' => $labels, | |
// Features this CPT supports in Post Editor | |
'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields' ), | |
// You can associate this CPT with a taxonomy or custom taxonomy. | |
'taxonomies' => array( 'genres' ), | |
/* A hierarchical CPT is like Pages and can have | |
* Parent and child items. A non-hierarchical CPT | |
* is like Posts. | |
*/ | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'show_in_nav_menus' => true, | |
'show_in_admin_bar' => true, | |
'menu_position' => 5, | |
'can_export' => true, | |
'has_archive' => false, | |
'exclude_from_search' => false, | |
'publicly_queryable' => true, | |
'capability_type' => 'post', | |
); | |
// Registering your Custom Post Type | |
register_post_type( 'leneros', $args ); | |
} | |
/* | |
* Creating Taxonomies for "Leneros" | |
* | |
*/ | |
function create_my_taxonomies() { | |
register_taxonomy( | |
'leneros_filters', | |
'leneros', | |
array( | |
'labels' => array( | |
'name' => 'Categoria de Leneros', | |
'add_new_item' => 'Nueva categoria', | |
'new_item_name' => "Nombre de categoria" | |
), | |
'show_ui' => true, | |
'show_tagcloud' => false, | |
'hierarchical' => true | |
) | |
); | |
} | |
add_action( 'init', 'create_my_taxonomies', 0 ); | |
/* Hook into the 'init' action so that the function | |
* Containing our post type registration is not | |
* unnecessarily executed. | |
*/ | |
add_action( 'init', 'custom_post_type_leneros', 0 ); | |
/* | |
* Register a new image size. | |
* Set the image size by cropping the image (not showing part of it) | |
*/ | |
if ( has_post_thumbnail() ) { | |
the_post_thumbnail( 'lenero-imagen' ); | |
} | |
add_image_size( 'lenero-imagen', 200, 200, true ); | |
/* | |
* Plugin for centroleneria.cl, render CPT Leneros to a Grid, with a Shortcode and attribute | |
* Original 010216, Version 0.1, | |
* Update 050416, Version 0.2, Ahora con update de filtros de sedes | |
*/ | |
function leneros_grid( $atts ) { | |
// Make out query work as a shortcode | |
ob_start(); | |
// Pass Shortcode Parameters Like So: [make-lenero-grid sede="seminario"] | |
$grid_atts = shortcode_atts( array( 'sede' => '', ), $atts ); | |
// Should pass on (in a secure manner), the parameter for our Query, regarding leneros_filters. | |
$filter = wp_kses_post( $grid_atts[ 'sede' ] ); | |
// Crete a custom query "WP_Query" with the $args passed later on in Variable "$loop" | |
$loop = new WP_Query( array( | |
'post_type' => 'leneros', | |
'leneros_filters' => $filter, | |
'posts_per_page' => -1, | |
'order' => 'DESC' ) ); | |
?> <!-- Start Leneros Grid loop --> | |
<section id="leneros-grid" style="padding-top:3em;"> | |
<div class="container tight"> | |
<h5 style="text-align: center;">Habitantes en | |
<?php | |
// Echo out our parameter and a statement for case null | |
if(!empty($filter)) { echo $filter; } else {echo "Leneria";} | |
?> | |
</h5> | |
<div class="contents-leneros" style="margin-top:2em;"> | |
<?php // Begin loop query | |
while ( $loop->have_posts() ) : $loop->the_post(); | |
echo "<div class=\"un-lenero". $class ." \">"; | |
if ( has_post_thumbnail() ) { | |
echo the_post_thumbnail('lenero-imagen'); | |
} else { | |
echo '<img src="http://placehold.it/200x200" alt="" />'; | |
} | |
echo "</a>"; | |
echo "<figure class=\"content\"><h5>" . get_the_content() . "</h5><ul class=\"lenero-grid-links\">"; | |
// Put a custom URL to a link | |
$custom_fields_url = get_post_custom(); | |
$my_custom_field_url = $custom_fields_url['url']; | |
if(isset($my_custom_field_url)) { | |
foreach ( $my_custom_field_url as $key => $value ) { | |
echo "<li><a class='link-externo web' target=\"_blank\" href=\"http://" . $value . "\"></a></li>"; | |
}} | |
// Put a custom URL to a Social Link | |
$custom_fields_social = get_post_custom(); | |
$my_custom_field_social = $custom_fields_social['redes']; | |
if(isset($my_custom_field_social)) { | |
foreach ( $my_custom_field_social as $key_a => $value_a ) { | |
echo "<li><a class='link-externo redes' target=\"_blank\" href=\"http://" . $value_a . "\"></a></li>"; | |
}} | |
// Put a custom mail address to a mail Link | |
$custom_fields_mail = get_post_custom(); | |
$my_custom_field_mail = $custom_fields_mail['mail']; | |
if(isset ($my_custom_field_mail)) { | |
foreach ( $my_custom_field_mail as $key_b => $value_b ) { | |
echo "<li><a class='link-externo mail' target=\"_blank\" href=\"mailto:" . $value_b . "\"></a></li>"; | |
}} | |
echo "</figure></div>"; | |
// End our custom Loop and reset Query | |
endwhile; wp_reset_query(); | |
?></div></div></section><!-- end Leneros grid Loop --> <?php | |
// Make out query work as a shortcode | |
$run_grid = ob_get_clean(); | |
return $run_grid; | |
} | |
// Create Shortcode for function | |
add_shortcode('make-lenero-grid','leneros_grid'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment