Exemplo n.º 1
0
/**
 * Muestra botones para compartir una página.
 * @param  array $atts  Redes sociales el
 * @return [type]       [description]
 */
function shortcodeCompartir($atts = array())
{
    $args = shortcode_atts(array('mostrar' => 'facebook,twitter,googleplus,whatsapp'), $atts);
    $redesMostradas = explode(',', $args['mostrar']);
    $retorno = array();
    // Clase del tag, url, nombre, contenido del tag
    $formato = '<a class="%s" href="%s" onclick="return !window.open(this.href, \'%s\', \'width=640,height=580\')">%s</a>';
    // Se los pasa por un loop para poder elegir el orden desde el shortcode.
    $permalink = get_the_permalink();
    $shortlink = wp_get_shortlink();
    foreach ($redesMostradas as $item) {
        if ($item == 'facebook') {
            $nombre = 'Facebook';
            $contenido = retornarSVG('facebook');
            $query = http_build_query(array('u' => $permalink, 'display' => 'popup', 'ref' => 'plugin', 'src' => 'share_button'));
            $url = 'https://www.facebook.com/sharer/sharer.php?' . $query;
            $retorno[] = sprintf($formato, 'compartir ' . $item, $url, $nombre, $contenido);
        }
        if ($item == 'twitter') {
            $nombre = 'Twitter';
            $contenido = retornarSVG('twitter');
            $query = http_build_query(array('status' => $shortlink));
            $url = 'https://twitter.com/home?' . $query;
            $retorno[] = sprintf($formato, 'compartir ' . $item, $url, $nombre, $contenido);
        }
        if ($item == 'googleplus') {
            $nombre = 'Google Plus';
            $contenido = retornarSVG('google-plus');
            $query = http_build_query(array('url' => get_the_permalink()));
            $url = 'https://plus.google.com/share?';
            $retorno[] = sprintf($formato, 'compartir ' . $item, $url . $query, $nombre, $contenido);
        }
        if ($item == 'whatsapp') {
            $nombre = 'WhatsApp';
            $contenido = retornarSVG('whatsapp');
            $query = http_build_query(array('text' => get_the_permalink()));
            $url = 'whatsapp://send?' . $query;
            $retorno[] = sprintf('<a class="%s" href="%s" rel="nofollow">%s</a>', 'compartir ' . $item, $url, $contenido);
        }
    }
    return implode('', $retorno);
}
Exemplo n.º 2
0
/**
 * Muestra el retorno de retornarSVG.
 * @param  string  $nombre    Nombre del archivo svg.
 * @param  boolean $incrustar Pone el contenido dentro de <span> o lo enlaza en <img>.
 * @return void
 */
function mostrarSVG($nombre, $incrustar = true)
{
    echo retornarSVG($nombre, $incrustar);
}
Exemplo n.º 3
0
    }
    ?>

                <?php 
    while (have_posts()) {
        the_post();
        ?>
                    <?php 
        the_content();
        ?>
                    <hr>
                    <table>
                    <?php 
        $svgs = array('facebook', 'facebook-circulo', 'facebook-cuadrado', 'google-plus', 'google-plus-circulo', 'google-plus-cuadrado', 'google-plus-cuadrado-alt', 'google-plus-nuevo', 'google-plus-nuevo-circulo', 'google-plus-nuevo-cuadrado', 'pinterest', 'pinterest-circulo', 'pinterest-cuadrado', 'twitter', 'twitter-circulo', 'twitter-cuadrado', 'whatsapp', 'whatsapp-circulo', 'whatsapp-cuadrado');
        foreach ($svgs as $svg) {
            echo '<tr><td>' . $svg . '</td><td>' . retornarSVG($svg) . '</td></tr>';
        }
        ?>
                    </table>
                <?php 
    }
    ?>

                <?php 
    if (comments_open() || get_comments_number()) {
        ?>
                    <?php 
        comments_template();
        ?>
                <?php 
    }