WordPress es una excelente opción como plataforma para tu blog, siendo casi un estándar, que te permite gestionar y administrar tu sitio de forma muy especÃfica, pudiendo además personalizarla por medio de plugins, extensiones o usando netamente código.
Ya vimos varias cuestiones de SEO o relacionadas con la seguridad en WordPress, en esta oportunidad hablaremos de qué trucos puedes lograr con PHP, por ejemplo, para cargar una hoja de estilos con valores dinámicos según cómo esté viendo la página el usuario y mucho más.¡Veamos qué tenemos!
Trucos PHP para tu blog de WordPress
Dirigiendo páginas de secciones a la primer sub página
<?php /* Template Name: Redirect To First Child */ if (have_posts()) { while (have_posts()) { the_post(); $pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order"); $firstchild = $pagekids[0]; wp_redirect(get_permalink($firstchild->ID)); } } ?>
Tomar el texto del contenido de una entrada (post) y darle estilo
/* * Grabs the text content from a Page that is meant to be a blurb * on another Page. * 1. Create a Page and insert text to be used as the blurb. * 2. Give the post slug a name. * 3. Call get_blurb() from where the blurb should be inserted. * * @param pagename - post slug of the Page * @param keeptags - tag list to allow in the text * @return String - the blurb */ function get_blurb ($pagename, $keeptags='') { $q = new WP_Query('pagename='.$pagename); $content = ''; if ($content = $q->queried_object->post_content) { $content = strip_tags($content, $keeptags); } else { $content = 'This blurb does not exist. '; } return $content; } function beautify_blurb ($content, $isIndex=FALSE) { if ($isIndex) { return preg_replace('/^<strong>/i', '<strong class="intro">',$content); } else { return preg_replace('/^ <strong>/i', ' <p class="intro"><strong>',$content); } }
Cargar una hoja de estilos con valores dinámicos dependiendo de la vista de página
/*** file: header.php ******************************/ <link rel="stylesheet" type="text/css" media="screen" href="<?php //Import stylesheet for the different pages if ( is_frontpage() || is_page('index') || preg_match( "#/index/#i" , $_SERVER['REQUEST_URI']) ) { print getdir().'/home.css'; } else { echo getdir().'/sub.css.php?p='; if ( is_home() || is_single() || is_archive() || preg_match("#/blog/#i",$_SERVER['REQUEST_URI']) ) print 'blog'; else { $post_parent = get_post($post->post_parent); print $post_parent->post_name; } } ?>" /> /*** file: sub.css.php ******************************/ <?php header('Content-type: text/css'); ?> div#sidebar_photo { background-image: url("images/sidebar_photo<?php if ( isset($_REQUEST['p']) ) { switch ($_REQUEST['p']) { case 'about': print '4'; break; case 'blog': print '5'; break; case 'team': print '1'; break; case 'products': print '6'; break; case 'howtobuy': print '3'; break; case 'spreadtheword': print '2'; break; case 'join': print '7'; break; case 'share': print '8'; break; default: print '1'; break; } } ?>.jpg"); }
Fecha y hora de expiración de un post
***BEFORE LOOP <?php $expirationtime = get_post_custom_values('expiration'); if (is_array($expirationtime)) { $expirestring = implode($expirationtime); } $secondsbetween = strtotime($expirestring)-time(); if ( $secondsbetween > 0 ) { ?> ***LOOP HERE*** ***AFTER LOOP*** <?php } ?>
¡Espero que te sean útiles!
Fuente: Stylizedweb








Comentarios recientes
- Juan Manuel: @Laura: sigue los pasos del comentario nº 2 ;)...
- Edison: Hola amigos muchas gracias por poner este bonito aporte aunque la pagina...
- ignacia ahumada: como se hace para adquirir el servicio...
- nic_net: Hola, creo que falta el link donde dice aquà :P
Un saludo!...
- Laura: Como se descargan los avatares de Simpsoniza Me?¿?...
- Daniel: No tengo ni idea espero aprender si luis me echa una mano...
Feed de los comentarios