Link to home
Start Free TrialLog in
Avatar of fajizzle
fajizzleFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to access page / post id and name in a Wordpress plugin

Hi,

I am writing my first wordpress plugin and need to know the following;

Is the current page a page or post
If it is a post, is it a summary page or the actual article.


I have gone through the functions list on the codex but nothing is jumping out at me but below is some code I am playing with .

Cheers
 	//display our widget
	function widget($args, $instance) {
		global $post;
		global $options;
		extract($args);
 
		echo $before_widget;
		
		$pageData = get_page( $page_id );
		$thisCat =  get_category(get_query_var('cat'),false);

		echo 'cat = ';
		echo $thisCat->name;
		echo '<br />';
		
		echo 'post type = ';
		echo $pageData->post_type;
		echo '<br />';
		
		
		echo 'pageID = ';
		echo $page_id;

		echo $pageData->post_name;
		echo '<br />';
		
				
		if($post->post_name != '') :
			echo '<div id="summary">';
			echo '<strong>Summary:</strong><br />';
			echo $post->post_name;
			echo '</div>';
		endif;

		
		
		/*
		if ($stream = fopen('http://what-music.com/wp-content/plugins/httpAPI/adsToServe.php','r')) {
			echo stream_get_contents($stream);
		}
		*/


		echo $after_widget;
	}
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dcowley
dcowley
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial