• Good, I have this plugin to display older, I am number extablecido a sample of older posts.

    But I get an error when trying to activate the plugin, the error is as follows.

    Parse error: parse error, expectingT_OLD_FUNCTION’ or T_FUNCTION' orT_VAR’ or '}'' in c:\localhost\easyphp1-8\www\wordpress2.6.5_es\wp-content\plugins\random_posts.php on line 8

    he code of the plugin random_posts.php is as follows.

    <?php
    /*
    Plugin Name: Random Posts
    */
    
    class RandomPost {
    
    	private $ids = array();
    	private $query;
    
    	function __construct( $posts , $not = null ){
    
    		global $wpdb, $tableposts;
    
    		if ( ctype_digit( $not ) ){
    			$this->query = $wpdb->get_results("SELECT <code>ID</code> FROM <code>$tableposts</code> WHERE <code>ID</code>!= $not AND<code>post_status</code>= 'publish' " );
    		}
    		elseif ( is_null( $not ) ){
    			$this->query = $wpdb->get_results("SELECT <code>ID</code> FROM <code>$tableposts</code> WHERE <code>post_status</code>= 'publish' " );
    		}
    		define( "_MAX_" , count( $this->query ) );
    
    		for ( $n = 0; $n < $posts; $n++ )
    		{
    			$this->ids[ $n ] = mt_rand( 0 , _MAX_ );
    			if ( $n > 0 )
    			{
    				for ( $w = 0; $w < $n; $w++ )
    				{
    					if( $this->ids[ $n ] == $this->ids[ $w ] )
    					{
    						$n --;
    						break;
    					}
    				}
    			}
    		}
    	}
    
    	public function the_link( $x )
    	{
    		$link = get_permalink( $this->query[ $this->ids[ $x ] ]->ID );
    		$post = get_post( $this->query[ $this->ids[ $x ] ]->ID );
    		$title = $post->post_title;
    ?>
    	   <li><a href="<?php echo $link; ?>" title="<?php echo $title; ?>"><?php echo $title; ?></a></li>
    <?
    	}
    }
    
    	function get_random_posts( $exclude , $num_posts = 15 ){
    		if ( ctype_digit( $exclude ) )
    			$post = new RandomPost( $num_posts , $exclude );
    		else
    			$post = new RandomPost( $num_posts );
    
    		for ( $x = 0; $x < $num_posts; $x++ ) {
    			$post->the_link( $x );
    		}
    		$post = null;
    	}
    
    ?>
  • The topic ‘Error fatal Plugin Random Posts’ is closed to new replies.