Mostrando entradas con la etiqueta Wordpress. Mostrar todas las entradas
Mostrando entradas con la etiqueta Wordpress. Mostrar todas las entradas

lunes, 16 de septiembre de 2013

Wordpress quitar tamaño fijo a las imagenes

Las imágenes de Wordpress se muestran con un tamaño fijo si no incluímos una función que lo evite.

En este ejemplo puede ver como Wordpress muestra las imágenes con tamaño fijo:

<img class="attachment-post-thumbnail wp-post-image nailthumb-image" alt="" src="" width="200" height="200">

El width y height fijo de las imágenes hace que un diseño responsive no funcione correctamente debido a que éstas permanecen con el mismo tamaño a pesar del tamaño de la pantalla.

Para evitar esto, debemos incluir la siguiente función en el archivo functions.php de nuestro theme:

//remove images size
function remove_dimensions( $html, $post_id, $post_image_id ) {
    $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    return $html;
}

add_filter( 'post_thumbnail_html', 'remove_dimensions', 10, 3 );

Es muy sencillo, al incluirla verás que las imágenes ya no tendran un ancho y altura fijo, permitiendo que el css defina su tamaño.


sábado, 14 de septiembre de 2013

Crear Custom Post Types en Wordpress

Los desarrolladores de Wordpress necesitan crear en multitples ocasiones diferentes tipos de post, para que el administrador pueda manipular las entradas de diferentes secciones del sitio de una forma ordenada.

Para ellos en el archivo functions.php de nuestro theme debemos ubicar funciones que le digan al core de Wordpress que necesitamos Custom Post Types.

Para ello simplemente debemos colocar una función de este estilo.

Código:

<?php

// Registramos el Custom Post Type
function artists_post_type() {

$labels = array(
'name'                => _x( 'Artists', 'Post Type General Name', 'text_domain' ),
'singular_name'       => _x( 'Artist', 'Post Type Singular Name', 'text_domain' ),
'menu_name'           => __( 'Artists', 'text_domain' ),
'parent_item_colon'   => __( 'Parent Product:', 'text_domain' ),
'all_items'           => __( 'All Artists', 'text_domain' ),
'view_item'           => __( 'View Artists', 'text_domain' ),
'add_new_item'        => __( 'Add New Artist', 'text_domain' ),
'add_new'             => __( 'New Artist', 'text_domain' ),
'edit_item'           => __( 'Edit Artist', 'text_domain' ),
'update_item'         => __( 'Update Artist', 'text_domain' ),
'search_items'        => __( 'Search artist', 'text_domain' ),
'not_found'           => __( 'No artists found', 'text_domain' ),
'not_found_in_trash'  => __( 'No artists found in Trash', 'text_domain' ),
);
   
    $rewrite = array(
    'slug'                => 'artist',
    'with_front'          => true,
    'pages'               => true,
    'feeds'               => true,
    );  
   
$args = array(
'label'               => __( 'Artists', 'text_domain' ),
'description'         => __( 'Artists list', 'text_domain' ),
'labels'              => $labels,
'supports'            => array( 'title', 'editor', 'thumbnail', ),
'hierarchical'        => false,
'public'              => true,
'show_ui'             => true,
'show_in_menu'        => true,
'show_in_nav_menus'   => true,
'show_in_admin_bar'   => true,
'menu_position'       => 5,
'menu_icon'           => 'icon url',
'can_export'          => true,
'has_archive'         => true,
'exclude_from_search' => false,
'publicly_queryable'  => true,
'query_var'           => 'artist',
        'rewrite'             => $rewrite,
'capability_type'     => 'post',
);
 
register_post_type( 'Artists', $args );


}

// Llamador de la función
add_action( 'init', 'artists_post_type', 0 );

?>

Como se puede ver en el código es una función para una supuesta sección de "Artistas", éste código permite crear el tipo de post "Artists". Y de esa manera organizar mejor tu sitio Wordpress.

Como ven se le envían parámetros a la función  register_post_type();

Recomiendo utilizar esta herramienta online y gratuita para generar el código solo llenando campos en un formulario. Aquí el link: http://generatewp.com/post-type/

Cualquier duda a consulta no dudes en dejar tu comentario en el post con gusto te ayudaré.