Commit b45a9878 authored by Esteban Choque's avatar Esteban Choque

Se incremento el tamaño de los items del carrusel

parents
Pipeline #1471 failed with stages
<?php
function carousel_create() {
// Save attachment ID
if ( isset( $_POST['submit_image_selector'] ) && isset( $_POST['image_attachment_id'] ) ) :
update_option( 'media_selector_attachment_id', absint( $_POST['image_attachment_id'] ) );
endif;
wp_enqueue_media();
$titulo = $_POST["titulo"];
$img_dest = $_POST["img_dest"];
$slug = $_POST["slug"];
//insert
if (isset($_POST['insert'])) {
global $wpdb;
$table_name = $wpdb->prefix . "home_bolivia_digital";
$wpdb->insert(
$table_name, //table
array('id' => $id, 'titulo' => $titulo, 'img_dest' => $img_dest, 'slug' => $slug), //data
array('%s', '%s', '%s', '%s') //data format
);
$message.="Item insertado";
}
?>
<link type="text/css" href="<?php echo WP_PLUGIN_URL; ?>/home-bolivia-digital/style-admin.css" rel="stylesheet" />
<div class="wrap">
<h2>Añadir Nuevo Item</h2>
<?php if (isset($message)): ?><div class="updated"><p><?php echo $message; ?></p></div><?php endif; ?>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<table class='wp-list-table widefat fixed'>
<tr>
<th class="ss-th-width">Título</th>
<td><input type="text" name="titulo" value="<?php echo $titulo; ?>" class="ss-field-width" /></td>
</tr>
<tr>
<th class="ss-th-width">Imágen Destacada</th>
<td>
<div class='image-preview-wrapper'>
<img id='image-preview' src='<?php echo $img_dest; ?>' height='100'>
</div>
<input id='img_dest' type="hidden" name="img_dest" value='<?php echo $img_dest; ?>' class="ss-field-width" />
<input id="upload_image_button" type="button" class="button" value="<?php _e( 'Establecer imagen destacada' ); ?>" />
</td>
</tr>
<tr>
<th class="ss-th-width">Slug</th>
<td><input type="text" name="slug" value="<?php echo $slug; ?>" class="ss-field-width" /></td>
</tr>
</table>
<input type='submit' name="insert" value='Guardar' class='button-primary'>
</form>
</div>
<?php
}
\ No newline at end of file
<?php
function carousel_list() {
?>
<link type="text/css" href="<?php echo WP_PLUGIN_URL; ?>/home-bolivia-digital/style-admin.css" rel="stylesheet" />
<div class="wrap">
<h2>Items</h2>
<div class="tablenav top">
<div class="alignleft actions">
<a href="<?php echo admin_url('admin.php?page=carousel_create'); ?>">Añadir Item</a>
</div>
<br class="clear">
</div>
<?php
global $wpdb;
$table_name = $wpdb->prefix . "home_bolivia_digital";
$rows = $wpdb->get_results("SELECT id, titulo, img_dest, slug from $table_name ORDER BY id DESC;");
?>
<table class='wp-list-table widefat fixed striped posts'>
<tr>
<th class="manage-column ss-list-width">ID</th>
<th class="manage-column ss-list-width">Titulo</th>
<th class="manage-column ss-list-width">Imágen Destacada</th>
<th class="manage-column ss-list-width">Slug</th>
<th>&nbsp;</th>
</tr>
<?php foreach ($rows as $row) { ?>
<tr>
<td class="manage-column ss-list-width"><?php echo $row->id; ?></td>
<td class="manage-column ss-list-width"><?php echo $row->titulo; ?></td>
<td class="manage-column ss-list-width"><?php echo $row->img_dest; ?></td>
<td class="manage-column ss-list-width"><?php echo $row->slug; ?></td>
<td><a href="<?php echo admin_url('admin.php?page=carousel_update&id=' . $row->id); ?>">Actualizar</a></td>
</tr>
<?php } ?>
</table>
</div>
<?php
}
\ No newline at end of file
<?php
function carousel_update() {
// Save attachment ID
if ( isset( $_POST['submit_image_selector'] ) && isset( $_POST['image_attachment_id'] ) ) :
update_option( 'media_selector_attachment_id', absint( $_POST['image_attachment_id'] ) );
endif;
wp_enqueue_media();
global $wpdb;
$table_name = $wpdb->prefix . "home_bolivia_digital";
$id = $_GET["id"];
$titulo = $_POST["titulo"];
$img_dest = $_POST["img_dest"];
$slug = $_POST["slug"];
//update
if (isset($_POST['update'])) {
$wpdb->update(
$table_name, //table
array('titulo' => $titulo, 'img_dest' => $img_dest, 'slug' => $slug), //data
array('ID' => $id), //where
array('%s', '%s', '%s', '%s'), //data format
array('%s') //where format
);
}
//delete
else if (isset($_POST['delete'])) {
$wpdb->query($wpdb->prepare("DELETE FROM $table_name WHERE id = %s", $id));
} else {//selecting value to update
$schools = $wpdb->get_results($wpdb->prepare("SELECT id, titulo, img_dest, slug from $table_name where id=%s", $id));
foreach ($schools as $s) {
$titulo = $s->titulo;
$img_dest = $s->img_dest;
$slug = $s->slug;
}
}
?>
<link type="text/css" href="<?php echo WP_PLUGIN_URL; ?>/home-bolivia-digital/style-admin.css" rel="stylesheet" />
<div class="wrap">
<h2>Items</h2>
<?php if ($_POST['delete']) { ?>
<div class="updated"><p>Item eliminado</p></div>
<a href="<?php echo admin_url('admin.php?page=carousel_list') ?>">&laquo; Volver al listado de items</a>
<?php } else if ($_POST['update']) { ?>
<div class="updated"><p>Item actualizado</p></div>
<a href="<?php echo admin_url('admin.php?page=carousel_list') ?>">&laquo; Volver al listado de items</a>
<?php } else { ?>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<table class='wp-list-table widefat fixed'>
<tr>
<th>Título</th>
<td><input type="text" name="titulo" value="<?php echo $titulo; ?>"/></td>
</tr>
<tr>
<th>Imágen Destacada</th>
<td>
<div class='image-preview-wrapper'>
<img id='image-preview' src='<?php echo $img_dest; ?>' height='100'>
</div>
<input id='img_dest' type="hidden" name="img_dest" value='<?php echo $img_dest; ?>' class="ss-field-width" />
<input id="upload_image_button" type="button" class="button" value="<?php _e( 'Establecer imagen destacada' ); ?>" />
</td>
</tr>
<tr>
<th>Slug</th>
<td><input type="text" name="slug" value="<?php echo $slug; ?>"/></td>
</tr>
</table>
<input type='submit' name="update" value='Guardar' class='button-primary'> &nbsp;&nbsp;
<input type='submit' name="delete" value='Eliminar' class='button' onclick="return confirm('&iquest;Est&aacute;s seguro de borrar este elemento?')">
</form>
<?php } ?>
</div>
<?php
}
\ No newline at end of file
CREATE TABLE IF NOT EXISTS `school` (
`id` varchar(3) CHARACTER SET utf8 NOT NULL,
`name` varchar(50) CHARACTER SET utf8 NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `school` (`id`, `name`) VALUES
('CCC', 'Corpus Christi Catholic School'),
('HSE', 'Holy Spirit Episcopal School'),
('OLG', 'Our Lady of Guadalupe Catholic School'),
('PLS', 'Pilgrim Lutheran School'),
('SAG', 'Saint Augustine Catholic School'),
('SAN', 'Saint Anne Catholic School'),
('SCC', 'Saint Christopher Catholic School'),
('TWC', 'The Woodlands Christian Academy');
\ No newline at end of file
<?php
/*
Plugin Name: Home Bolivia Digital
Description: Carousel del portal Bolivia Digital
Version: 1
Author: esteban.com
Author URI: http://esteban.com
*/
// function to create the DB / Options / Defaults
function carousel_options_install() {
global $wpdb;
$table_name = $wpdb->prefix . "home_bolivia_digital";
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
`id` INT(6) NOT NULL AUTO_INCREMENT,
`titulo` TEXT CHARACTER SET utf8 NOT NULL,
`img_dest` TEXT CHARACTER SET utf8 NOT NULL,
`slug` TEXT CHARACTER SET utf8 NOT NULL,
PRIMARY KEY (`id`)
) $charset_collate; ";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta($sql);
}
// run the install scripts upon plugin activation
register_activation_hook(__FILE__, 'carousel_options_install');
//menu items
add_action('admin_menu','carousel_modifymenu');
function carousel_modifymenu() {
//this is the main item for the menu
add_menu_page('Carrusel', //page title
'Carrusel', //menu title
'manage_options', //capabilities
'carousel_list', //menu slug
'carousel_list' //function
);
//this is a submenu
add_submenu_page('carousel_list', //parent slug
'Añadir Nuevo Item', //page title
'Añadir Nuevo Item', //menu title
'manage_options', //capability
'carousel_create', //menu slug
'carousel_create'); //function
//this submenu is HIDDEN, however, we need to add it anyways
add_submenu_page(null, //parent slug
'Actualizar Item', //page title
'Actualizar', //menu title
'manage_options', //capability
'carousel_update', //menu slug
'carousel_update'); //function
}
define('ROOTDIRHBD', plugin_dir_path(__FILE__));
require_once(ROOTDIRHBD . 'carousel-list.php');
require_once(ROOTDIRHBD . 'carousel-create.php');
require_once(ROOTDIRHBD . 'carousel-update.php');
//Funcion para obtener los foros
add_action( 'rest_api_init', 'carousel_route' );
function carousel_route() {
register_rest_route( 'carousel','v1', array(
'methods' => 'GET',
'callback' => 'carousel',
)
);
}
function carousel() {
global $wpdb;
$table_name = $wpdb->prefix . "home_bolivia_digital";
$rows = $wpdb->get_results("SELECT t.id, t.titulo, t.img_dest, t.slug from $table_name t ORDER BY t.id DESC LIMIT 10;");
$datos = array();
$i = 0;
foreach ($rows as $row) {
$datos[$i][ 'id' ] = $row->id;
$datos[$i][ 'titulo' ] = $row->titulo;
$datos[$i][ 'img_dest' ] = $row->img_dest;
$datos[$i][ 'slug' ] = $row->slug;
$i++;
}
return rest_ensure_response( $datos );
}
\ No newline at end of file
.widefat {width: auto;}
.ss-list-width {min-width:10%}
.ss-form-width {width:100%}
.ss-th-width {width:25%}
.ss-field-width {width:75%}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment