• chriseriksson

    (@chriseriksson)


    Hi,
    Im no good at php but managed to get a php script located in my theme-folder (the theme im using) to spit out an xml with information i wanted, iex: title, copy, images etc.

    The only problem im getting is that when i first connect to get access to everything:

    <?php
    	require_once( '../../../wp-config.php' );

    It automatically spits out “https://www.mydomain.com”*entries. For example, if i have 3 entries in my blog it spits out “https://www.mydomain.comhttps://www.mydomain.comhttps://www.mydomain.com&#8221;

    All i want is to be able to ONLY echo out what i define without this nasty little extra bit getting spat out in the very first line of my xml.

    Here is my entire code if that helps:

    <?php
    	// get connected
    	require_once( '../../../wp-config.php' );
    
    	//header('Content-type: application/xml');
    
    	// variables
    	$xml = "";
    	$num_of_posts_to_display = 500;
    
    	$xml .= '<madeofus>';
    	$xml .= '<blog>';
    
    	// query posts
    	query_posts( 'showposts=' . $num_of_posts_to_display . '&post_type=post&post_status=publish&order=DESC' );
    
    	if( have_posts() ) : while( have_posts() ) : the_post();
    
    		// category ID
    		$category = get_the_category();
    
    		// get first thumbnail path
    		preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i', $post->post_content, $m );
    
    		// format XML
    		$xml .= '<item>';
    		$xml .= '<title>' . $post->post_title . '</title>';
    		$xml .= '<postlink>' . get_permalink() . '</postlink>';
    
    		$xml .= '<gallery>';
    		if( $m[ 1 ][ 0 ] ) $xml .= '<image_1>' . $m[ 1 ][ 0 ] . '</image_1>';
    		if( $m[ 1 ][ 1 ] ) $xml .= '<image_2>' . $m[ 1 ][ 1 ] . '</image_2>';
    		if( $m[ 1 ][ 2 ] ) $xml .= '<image_3>' . $m[ 1 ][ 2 ] . '</image_3>';
    		if( $m[ 1 ][ 3 ] ) $xml .= '<image_4>' . $m[ 1 ][ 3 ] . '</image_4>';
    		if( $m[ 1 ][ 4 ] ) $xml .= '<image_5>' . $m[ 1 ][ 4 ] . '</image_5>';
    		if( $m[ 1 ][ 5 ] ) $xml .= '<image_6>' . $m[ 1 ][ 5 ] . '</image_6>';
    		if( $m[ 1 ][ 6 ] ) $xml .= '<image_7>' . $m[ 1 ][ 6 ] . '</image_7>';
    		if( $m[ 1 ][ 7 ] ) $xml .= '<image_8>' . $m[ 1 ][ 7 ] . '</image_8>';
    		if( $m[ 1 ][ 8 ] ) $xml .= '<image_9>' . $m[ 1 ][ 8 ] . '</image_9>';
    		$xml .= '</gallery>';
    
    		$xml .= '<category>' . $category[ 0 ]->cat_name . '</category>';
    		$xml .= '<catid>' . bloginfo( 'home' ) . '?cat=' . $category[ 0 ]->cat_ID . '</catid>';
    		$xml .= '<date>' . date( 'M j, Y', strtotime( $post->post_date ) ) . '</date>';
    		$xml .= '<comments>' . $post->comment_count . '</comments>';
    		$xml .= '<excerpt>' . wp_trim_excerpt( get_the_excerpt() ) . '</excerpt>';
    		$xml .= '</item>';
    
    	endwhile; endif;
    	$xml .= '</blog>';
    	$xml .= '</madeofus>';
    
    	// output results
    	echo $xml;
    
    ?>

    Any help is much appreciated!

    Thanks,
    Chris

  • The topic ‘Echoing out xml for use in flash’ is closed to new replies.