• Resolvido mauriciomesquita

    (@mauriciomesquita)


    Gostaria de inserir a URL da miniatura de um post no meu feed

    Ou seja, quero que no arquivo XML seja adicionada uma tag apenas com a url da miniatura.

    EX:
    <imageurl>http://urldaminiatura </imageurl>

    Isso é possível?

    Sei que alterando o arquivo functions.php do tema e adicionando o seguinte código dá. Só que eu gostaria que fosse criada uma nova tag no XML apenas com a URL da miniatura.

    // mostra thumbnails no feed
    function my_post_thumbnail_feeds($content) {
      global $post;
      if(has_post_thumbnail($post->ID)) {
        $content = '<div>' . get_the_post_thumbnail($post->ID) . '</div>' . $content;
      }
      return $content;
    }
    add_filter('the_excerpt_rss', 'my_post_thumbnail_feeds');
    add_filter('the_content_feed', 'my_post_thumbnail_feeds');
Visualizando 2 respostas - 1 até 2 (de um total de 2)
  • Criador do tópico mauriciomesquita

    (@mauriciomesquita)

    Compreendem?

    No arquivo XML, que é o meu feed gostaria de inserir uma tag que contenha só o endereço da URL da imagem da miniatura.

    <imageurl>http:// .... miniatura.jpg </imageurl>

    e segue o xml normal…

    Criador do tópico mauriciomesquita

    (@mauriciomesquita)

    Consegui criar uma tag no XML do meu feed contendo a URL da miniatura. Adaptei um plugin. Ele cria uma tag no XML do feed <imageurl></imageurl>. Se o cara postar uma miniatura fica a url da miniatura, se ele não postar fica a URL de uma imagem padrão. Segue código do plugin adaptado:

    <?php
    /*
    Plugin Name:  Feed Thumbnails
    Description:  Adds your post thumbnails to your feed as enclosures.
    Plugin URI:   http://lud.icro.us/wordpress-plugin-feed-thumbnails/
    Version:      1.2
    Author:       John Blackbourn
    Author URI:   http://johnblackbourn.com/
    
    	This program is free software; you can redistribute it and/or modify
    	it under the terms of the GNU General Public License as published by
    	the Free Software Foundation; either version 2 of the License, or
    	(at your option) any later version.
    
    	This program is distributed in the hope that it will be useful,
    	but WITHOUT ANY WARRANTY; without even the implied warranty of
    	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    	GNU General Public License for more details.
    
    */
    
    function feed_thumbnails() {
    
    	if ( function_exists( 'get_the_image' ) and ( $thumb = get_the_image('format=array&echo=0') ) ) {
    		$thumb[0] = $thumb['url'];
    	} else if ( function_exists( 'has_post_thumbnail' ) and has_post_thumbnail() ) {
    		$thumb = wp_get_attachment_image_src( get_post_thumbnail_id(), 'post-thumbnail' );
    	} else if ( function_exists( 'get_post_thumbnail_src' ) ) {
    		$thumb = get_post_thumbnail_src();
    		if ( preg_match( '|^<img src="([^"]+)"|', $thumb[0], $m ) )
    			$thumb[0] = $m[1];
    	} else {
    		$thumb = false;
    	}
    
    	if ( !empty( $thumb ) ) {
    		echo "\t" . '<imageurl>' . $thumb[0] . '</imageurl>' . "\n";
    
    	}else {
    	echo "\t<imageurl>URL Imagem Padrão.gif</imageurl> \n"; }
    
    }
    
    add_action( 'rss2_item', 'feed_thumbnails' );
    
    ?>

    Se alguém tiver um jeito que dê uma volta menor. Por favor. 🙂

Visualizando 2 respostas - 1 até 2 (de um total de 2)

O tópico ‘miniatura no feed’ está fechado para novas respostas.