Recent Topics

1 Feb 19, 2012 23:30    

Facebook often mistakes info (title - desc) & preview picture in b2 blog, since we dont have a fb plugin yet (:

However the mistaken preview picture is very misleading for photoblog posts.

So the question is, in single post mode, have to add sth like:

<meta property="og:image" content="http://the-image-linked-to-post">

Ideas ?

2 Feb 28, 2012 06:00

Edit /skins/yourskin/_skin.class.php file

function display_init()
{
	global $blog, $disp;
	
	// call parent:
	parent::display_init();

	if( $blog == 332 && $disp == 'single' )
	{
		// If requested blog is #332 and it's a single post
		add_headline('<meta property="og:image" content="http://the-image-linked-to-post">');
	}
}

You should already have this file in your skin folder. If not, find similar skin and copy that file from it, make sure you edit the class name.

3 Feb 28, 2012 10:33

Okay thanks.
but http://the-image-linked-to-post should be dynamic, the thumbnail of photoblog post image sth like
<meta og:image content="post->linked_image"> or
<meta og:image content="post->small_avatar">

Is there sth like "add_headline" that we can use in index.main or posts.main.php ? Because we have to generate different og tags for every post in the post loop.

4 Feb 28, 2012 17:06

The $Item object is available in single mode. You may try this

if( $blog == 332 && $disp == 'single' )
{   // If requested blog is #332 and it's a single post
	if( !empty($Item) )
	{	// Make sure the Item is loaded
		if( $FileList = $Item->get_attachment_FileList(20) )
		{	// Get 20 attached files (there might be non-images so we try them all)
			while( $File = & $FileList->get_next() )
			{	// Loop through attached files
				if( $File->exists() && $File->is_image() )
				{	// Got an image
					$url = $File->get_url();
					break;
				}
			}
		}
	}
	
	if( !empty($url) )
	{
		add_headline('<meta property="og:image" content="'.$url.'">');
	}
}

5 Feb 28, 2012 17:07

You can get post avatar the same way

6 Feb 28, 2012 19:00

you missed the 5th } above, added that, but still not working

7 Feb 28, 2012 19:48

The last 5th } should be at the very bottom, and it's there unless you already edited my reply.

Anyway, I will check that

8 Feb 28, 2012 19:56

Ok, I found a problem. You are using PHP 4.4.9 which is very old. See if you can select PHP 5 in your hosting control panel.

9 Feb 28, 2012 19:58

Disregard that, wrong topic :)

10 Mar 05, 2012 07:17

sam2kb wrote:

The $Item object is available in single mode. You may try this

if( $blog == 332 && $disp == 'single' )
{   // If requested blog is #332 and it's a single post
	if( !empty($Item) )
	{	// Make sure the Item is loaded
		if( $FileList = $Item->get_attachment_FileList(20) )
		{	// Get 20 attached files (there might be non-images so we try them all)
			while( $File = & $FileList->get_next() )
			{	// Loop through attached files
				if( $File->exists() && $File->is_image() )
				{	// Got an image
					$url = $File->get_url();
					break;
				}
			}
		}
	}
	
	if( !empty($url) )
	{
		add_headline('<meta property="og:image" content="'.$url.'">');
	}
}

do i insert this in skin.class.php, inside

	function display_init()
	{


after

		// call parent:
		parent::display_init();

Or inside template files ?

13 Mar 05, 2012 17:44

Add $Item to globals.

global $blog, $disp, $Item;

15 Mar 06, 2012 10:51

You can display one post per page, however you can't just force 'single' mode if no target post requested.

What you need is rewrite the code I posted to get the first Item from MainList rather than using a global $Item object.

Something like this

if( $blog == 332 && !empty($MainList) && $MainList->results_num_rows > 0 )
{   // If requested blog is #332 and we have some posts to display
    if( $Item = $MainList->get_first() )
    {    // Get the first (and the only in our case) Item
        if( $FileList = $Item->get_attachment_FileList(20) )
        {    // Get 20 attached files (there might be non-images so we try them all)
            while( $File = & $FileList->get_next() )
            {    // Loop through attached files
                if( $File->exists() && $File->is_image() )
                {    // Got an image
                    $url = $File->get_url();
                    break;
                }
            }
        }
    }
    
    if( !empty($url) )
    {
        add_headline('<meta property="og:image" content="'.$url.'">');
    }
}

untested

Then setup the blog to display 1 post per page

16 Jul 03, 2012 00:06

sam2kb wrote:

You can get post avatar the same way

your above worked pretty good for the photoblog, how can i get the post avatars to display right ?

17 Jul 03, 2012 00:19

Try this

if( $blog == 332 && !empty($MainList) && $MainList->results_num_rows > 0 )
{   // If requested blog is #332 and we have some posts to display
    if( $Item = $MainList->get_first() )
    {    // Get the first (and the only in our case) Item
        if ( isset($GLOBALS['avatars_Plugin']) )
		{	// Avatars plugin enabled
			if( ($avatar = $GLOBALS['avatars_Plugin']->get_avatar( 'post', $Item->ID )) !== NULL )
			{	// Get post avatar
				$url = $avatar['url'];
			}
		}
    }
    
    if( !empty($url) )
    {
        add_headline('<meta property="og:image" content="'.$url.'">');
    }
}


Form is loading...