Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

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

0
fajizzle
Asked:
fajizzle
1 Solution
 
dcowleyCommented:
I think what you're looking for is the template conditional tags (http://codex.wordpress.org/Conditional_Tags)

is_single()  (e.g. not a summary page)
is_page() (is it a page?)

Check the rest of the page, there's probably one which matches your specific needs, or a combination of them...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now