How to return the Article ID?

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
holmesjl
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Thu Feb 05, 2009 5:11 pm

How to return the Article ID?

Post by holmesjl » Tue Mar 17, 2009 12:29 pm

I am creating a sort of breadcrumbs module that supports subcats and was wondering how to pull the article id of the current page being visited. Any thoughts? Thanks

kharmer
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 110
Joined: Thu Feb 19, 2009 9:57 am
Location: Cambridgeshire / Hertfordshire, Great Britain, Centre of the Universe
Contact:

Re: How to return the Article ID?

Post by kharmer » Tue Mar 17, 2009 12:45 pm

From a template, or from a view in a component or module for that matter, you could simply grab it from the URL params like so:

Code: Select all

echo("Content ID: ".$_GET['id']);
Kris...
Joomla CMS Developer: http://www.kharmer.co.uk

holmesjl
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Thu Feb 05, 2009 5:11 pm

Re: How to return the Article ID?

Post by holmesjl » Tue Mar 17, 2009 1:14 pm

That works sometimes however on some articles I get
"46:whats-new-in-15"
instead of just the article ID number
"46"
or sometimes I don't get an output at all.

I'm looking to just get the id number from the page so I could query the db with it. I will look into substring however not getting a response is not good. oh, just thought of it, if I browse to a section of category page it wouldn't have an article ID. So how could I pull the section id, category ID, and article ID?

User avatar
whitevirus
Joomla! Explorer
Joomla! Explorer
Posts: 274
Joined: Thu Apr 24, 2008 1:58 pm

Re: How to return the Article ID?

Post by whitevirus » Tue Mar 17, 2009 1:57 pm

You should use
$id=JRequest::getVar('id',0);

holmesjl
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Thu Feb 05, 2009 5:11 pm

Re: How to return the Article ID?

Post by holmesjl » Tue Mar 17, 2009 2:21 pm

Thanks guys!

That seems to give me the same result as the earlier post. However, I can make it work with using a substring function.

Would anyone happen to know how to display the category id of a page?
I would like to use the category listing page.

DeZzL
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Fri Jun 02, 2006 12:37 pm
Contact:

Re: How to return the Article ID?

Post by DeZzL » Thu Mar 19, 2009 1:13 pm

Code: Select all

$categoryid = JRequest::getVar( 'category' )
edit: Never mind, I didn't read carefully.

ybong
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 237
Joined: Wed Feb 11, 2009 3:32 am
Location: Malaysia

Re: How to return the Article ID?

Post by ybong » Fri Mar 20, 2009 1:31 am

Hi,

To do so you can check your database, under jos_content table. There are 3 field that you might need to retrieve which are:
1. SectionID
2. CatID
3. ParentID

Get the information accordingly and display it.

The first problem that you face might cause by table joining issue. If the data that you retrieve is more then one table, please name the fields accordingly to get the correct id. :)

Hope this helps you.

Regards,
YB
Regards,
YB


Locked

Return to “Joomla! 1.5 Coding”