Solved

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

Posted on 2012-03-13
1
280 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 500 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

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wordpress Taxonomy 2 52
AdminLTE with wordpress 15 360
google analytics on wp-admin password protected area 2 74
Change Wording in Wordpress Plugin 4 38
Did you use a default hosting installation of wordpress with the intention of it being your actual site?  Maybe you’ve installed it as a Blog to your current site and recently converted it to be the main site and do away with the old .htm pages.  An…
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

734 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