• Hi !

    I am writing a plugin that displays links to the latest posts via aScroller Javascript newsTicker.

    To achieve that, I want that everytime a post is published the plugins generates a text file with the content extracted from the lasts posts.

    with the code below, I am able to generate the file, but it still outputs me an error:

    Warning: Cannot modify header information – headers already sent by (output started at /Applications/MAMP/htdocs/decideursTV2/wp-includes/link-template.php:5) in /Applications/MAMP/htdocs/decideursTV2/wp-includes/pluggable.php on line 694

    here is my code:

    <?php
    /*
    Plugin Name: NewsTicker
    Plugin URI: https://
    Description: Récupère Flux RSS et met en forme et en cache un fichier texte exploité par le ticker.
    Author: Nicolas Roos
    Version: 0.1
    Author URI: https://
    
    */
    
    add_action('wp_head','addAscroller');
    
    add_action('publish_post','update_ticker');
    
    function addAscroller() {
    	echo '<script src="'.bloginfo('blog_url').'/wp-content/nesTicker/aScroller-1.0.js"></script>';
    }
    
    function update_ticker() {
    	$tickerContent = '';
    	$my_query = new WP_Query('showposts=20');
    	while ($my_query->have_posts()) : $my_query->the_post();
    	$do_not_duplicate = $post->ID;
    	    	$tickerContent .= '<a href="'.the_permalink().'" title="'.the_title().'">'.the_title().'</a>&nbsp;&nbsp;-&nbsp;&nbsp;';
     	 endwhile;
    
    	$tickerFile = bloginfo('url')."/newsTicker.txt";
    	$fh = fopen($tickerFile, 'a');
    	fwrite($fh,$tickerContent);
    	fclose($fh);
    }
    ?>

    I am sure someone can help me. Maybe It’s the Javascript include that’s causing the problem…

Viewing 1 replies (of 1 total)
  • Thread Starter nicosFR

    (@nicosfr)

    I got it working with this code

    <?php
    /*
    Plugin Name: NewsTicker
    Plugin URI: https://
    Description: Récupère Flux RSS et met en forme et en cache un fichier texte exploité par le ticker.
    Author: Nicolas Roos
    Version: 0.1
    Author URI: https://
    
    */
    
    add_action('wp_head','addAscroller');
    
    add_action('publish_post','update_ticker');
    
    function addAscroller() {
    	echo '<script src="'.bloginfo('blog_url').'/wp-content/nesTicker/aScroller-1.0.js"></script>';
    }
    
    function update_ticker() {
    	$tickerContent = '';
    	$my_query = new WP_Query('showposts=20');
    	while ($my_query->have_posts()) : $my_query->the_post();
    	$do_not_duplicate = $post->ID;
    		$title= the_title("", "", false);
    	    $tickerContent .= '<a href="'.get_permalink().'" title="'.$title.'">'.$title.'</a>&nbsp;&nbsp;-&nbsp;&nbsp;';
     	endwhile;
    	$tickerFile = "newsTicker.txt";
    	$fh = fopen($tickerFile, 'a');
    	fwrite($fh,$tickerContent);
    	fclose($fh);
    }
    ?>

    I’ll work on a generic version of this plugin and offer it with a fully customisable interface.

Viewing 1 replies (of 1 total)
  • The topic ‘Helb building a newsTicker plugin’ is closed to new replies.