Recent Topics

Call a post by id

Started by on Jun 13, 2011 – Contents updated: Jun 13, 2011

Jun 13, 2011 07:56    

Hi, what code can I use if I want to call a specific post, like for instance I have 200 posts and I would like to call post item with id 44

Jun 13, 2011 20:11

PHP

$ItemCache = & get_ItemCache();
$Item = & $ItemCache->get_by_ID(44);

If you are not sure that particular Item exists, use this instead

PHP

if( $Item = & $ItemCache->get_by_ID44false ) )
{
    // Valid Item
}

Same applies to Blog, Skin, Chapter (category)

PHP

$BlogCache = & get_BlogCache();
$Blog = & $BlogCache->get_by_ID(44);

Jul 06, 2011 17:47

What if I want to display the id for the currant post being viewed like when using

PHP

$Blog->ID
, instead of viewing the id for the currant blog displayed, you will view the id for the currant post displayed?

perhaps:

PHP

$Item->ID

Jul 06, 2011 20:52

Got it thanks.

PHP

global $Blog$Item;
        $this_blog $Blog->ID;
        $this_post $Item->ID;

Jul 06, 2011 23:56

$Item object is only defined globally (not in post loop) only in a single post/page view. Use this additional check.

PHP

global $Blog$Item;
$this_blog $Blog->ID;
 
if( !empty($Item) )
{
    $this_post $Item->ID;
}

Jul 07, 2011 15:25

Updated, thanks. (:

I only need it in this instance for single post view and pages, modified images linked to posts to display in either thumb or not and list view or grid. (similar to media index), but instead only images for the post viewed.

Integrated it with a lightbox, so images linked to a post are now displayed as a gallery. Works great and looks nifty.


Form is loading...

b2evo – This forum is powered by b2evolution CMS, a complete engine for your website.