Solved

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

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Now that you've installed WordPress 2.9 (http://www.experts-exchange.com/articles/Web_Development/Blogs/WordPress/WordPress-2-9-What-to-Expect-When-Upgrading-to-WordPress-2-9.html?) on your site, you need to install some plugins to get the most out …
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now