1 tilqicom Feb 19, 2012 23:30
3 tilqicom 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 sam2kb 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 sam2kb Feb 28, 2012 17:07
You can get post avatar the same way
6 tilqicom Feb 28, 2012 19:00
you missed the 5th } above, added that, but still not working
7 sam2kb 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 sam2kb 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 sam2kb Feb 28, 2012 19:58
Disregard that, wrong topic :)
10 tilqicom 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 ?
11 sam2kb Mar 05, 2012 08:14
The code goes in _skin.class.php as I noted before
http://forums.b2evolution.net/viewtopic.php?p=112586#112586
12 tilqicom Mar 05, 2012 10:05
sam2kb wrote:
The code goes in _skin.class.php as I noted before
http://forums.b2evolution.net/viewtopic.php?p=112586#112586
Yea i assumed so, but it doesnt work.
- - -
The one in the below post works though, but it doesnt actually do any good since it doesnt get any attached image or anything.
13 sam2kb Mar 05, 2012 17:44
Add $Item to globals.
global $blog, $disp, $Item;
14 tilqicom Mar 06, 2012 10:39
Yea forgot that.It works now in single mode.As we cannot declare multiple og tags in one page, afaik, it's impossible to do this for "posts" page.
So, Now i have to find a way to display blog in single mode by default.As i mentioned here.
15 sam2kb 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 tilqicom 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 sam2kb 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.'">');
}
}
18 tilqicom Jul 03, 2012 13:03
seems to work, thanks
Edit /skins/yourskin/_skin.class.php file
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.