?
Solved

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

Posted on 2012-03-13
1
Medium Priority
?
285 Views
Last Modified: 2012-03-22
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
Comment
Question by:fajizzle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
dcowley earned 1500 total points
ID: 37722447
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Transferring a wordpress site from a host or local dev server to another host can be a pain. So I've included my steps on how I have accomplished this task. Steps include an assumption that you have Cpanel access or Ftp access.. If you do not hav…
WordPress can be pretty daunting, especially for a beginner, so I thought it might be a good idea to write an article to show how easy it is to get started in WordPress and to design a custom theme.  The first step is to check with your hosting comp…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question