955 325 241 - 656 26 01 65

Mapa del Sitio Compartir RSS Mailing List

Carrusel de páginas especificas en theme wordpress
Imprimir  
0
Categoría Hacks & Mods, Themes & Templates
Escrito el Martes 29 may 2012 por Pedro J. Martín Villalba

Atendiendo a la estructura de nuestros themes con carrusel, y al artículo http://www.fcsites.com/themes-templates/personalizar-listados-de-paginasentradas-en-wordpress-carrusel-pho2-theme/ en que os decíamos como personalizar el carrusel para que aparecieran páginas en lugar de entradas, hemos ido un paso más allá a raíz de la necesidad de un cliente, de seleccionar las páginas que quería que aparecieran en el carrusel.

El procedimiento es bastante sencillo. En primer lugar, hemos creado la página de opciones del theme con el código (recuerda sustituir “mytheme” por el nombre de tu theme):


<?php

add_action( 'admin_init', 'theme_options_init' );
add_action( 'admin_menu', 'theme_options_add_page' );

/**
 * Init plugin options to white list our options
 */
function theme_options_init(){
 register_setting( 'sample_options', 'mytheme_theme_options', 'theme_options_validate' );
}

/**
 * Load up the menu page
 */
function theme_options_add_page() {
 add_theme_page( __( 'Carrousel', 'mytheme' ), __( 'Carrousel', 'mytheme' ), 'edit_theme_options', 'theme_options', 'theme_options_do_page' );
}
/**
 * Create the options page
 */
function theme_options_do_page() {
 global $select_options, $radio_options;

if ( ! isset( $_REQUEST['settings-updated'] ) )
 $_REQUEST['settings-updated'] = false;

?>
 <div class="wrap">
 <?php screen_icon(); echo "<h2>" . get_current_theme() . __( ' Theme Options', 'mytheme' ) . "</h2>"; ?>

<?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
 <div class="updated fade"><p><strong><?php _e( 'Options saved', 'mytheme' ); ?></strong></p></div>
 <?php endif; ?>

<form method="post" action="options.php">
 <?php settings_fields( 'sample_options' ); ?>
 <?php $options = get_option( 'mytheme_theme_options' ); ?>

<table class="form-table">

<?php
 /**
 * A sample text input option
 */
 ?>
 <tr valign="top"><th scope="row"><?php _e( 'FrontPage Carrousel page IDs', 'mytheme' ); ?></th>
 <td>
 <input id="mytheme_theme_options[carrousel]" class="regular-text" type="text" name="mythemeo_theme_options[carrousel]" value="<?php esc_attr_e( $options['carrousel'] ); ?>" />
 <label class="description" for="mytheme_theme_options[carrousel]"><?php _e( 'Write: 41,44,50,95 (for ex)', 'mytheme' ); ?></label>
 </td>
 </tr>
 </table>

<p class="submit">
 <input type="submit" class="button-primary" value="<?php _e( 'Save Options', 'mytheme' ); ?>" />
 </p>
 </form>
 </div>
 <?php
}

/**
 * Sanitize and validate input. Accepts an array, return a sanitized array.
 */
function theme_options_validate( $input ) {
 global $select_options, $radio_options;
// Say our text option must be safe text with no HTML tags
 $input['carrousel'] = wp_filter_nohtml_kses( $input['carrousel'] );
 return $input;
}

?>

En segundo lugar, la llamamos para que cargue incluyendo estas lineas en functions.php


// Opciones del tema, paginas que se muestran en Carrusel
require_once ( get_template_directory() . '/theme-options.php' );

Ahora solo nos queda sustituir el array a las páginas específicas en index.php, sustituimos pues el código:

$certain_pages = array(...);

por el siguiente:


$options = get_option('mytheme_theme_options');
$certain_pages = explode(',',$options['carrousel']);

Y así, el cliente podrá tener una pantalla en el backend desde la que especificar las páginas que quiere que se muestren en el carrusel de Pho2.

Muy bueno, no? :)

Autor
Contactar con Pedro J. Martín Villalba
Propietario de la marca comercial FCSITES (diseñador web freelance workaholic con +15 años de experiencia profesional). Aficionado a las artes marciales y conocido como "Formado Comprido" en el mundo de la capoeira. Autor del libro en español: "Ao som do berimbau: Capoeira".

Imprimir  


  • Hosting

    Alojamiento Web

    desde 40€/año

    Paquetes de alojamiento web estandar y personzalidos
  • Páginas Web

    Websites

    desde 34,90€/mes

    Diseño web profesional, webs presenciales, cms y portales
  • Tiendas

    Tiendas Virtuales

    desde 54,90€/mes

    La oferta de Tienda Virtual más completa del sector
  • SEO

    Promoción SEO

    desde 340€/t

    Promoción y optimización para motores de búsqueda
  • Scripts

    Instalación de scripts

    desde 399€

    Instalación, configuración y personalización de scripts