1 poopoo Aug 28, 2006 20:43
3 poopoo Aug 28, 2006 21:02
sorry for the wrong forum,
thanks for the reply...
Why is it so hard to do? not that I question your skills... :roll:
4 balupton Aug 28, 2006 21:11
Well....
We would need to find whatever your last post was.
Then scan it for <img> tags.
Then pick one of them.
And then display it.
I guess it wouldn't be that hard.
But it would still need to be made, so you wouldn't find it as "an easy cut and paste way".
So yeh....
So far, every developer here is very busy with our own things, so the best way of getting this done, would be if you became a developer ;)
Hope this helps :)
5 poopoo Aug 28, 2006 21:17
yeah, that helps... but what i was euding to was that I noticed that it was done with earlier versions...what has changed in 1.8 that nolonger allows older methods to werk?
thanks again
6 balupton Aug 28, 2006 21:19
Hrm... If it was done in previous versions could you attach a link to where it was done, and i'll look into it.
7 poopoo Aug 28, 2006 21:20
8 balupton Aug 28, 2006 21:40
Ahh ok, i'll give Yabba a buzz.
9 stk Aug 29, 2006 17:44
poopoo,
The random image in the sidebar was one of the first hacks I made for b2evolution. The original post for that can be found [url=http://forums.b2evolution.net/viewtopic.php?t=3147]HERE[/url], which might provide some insight into how the thing was developed.
I'm still using the same code that's pasted there in the [url=http://www.randsco.com/index.php/2005/03/06/random_picture]online tutorial/post[/url], only modified slightly for v1.8 .... here's the latest from my _main.php file:
<?php
//mysql_query('drop table evo_temp');
// create a temp table & fill it w/posts having pics (from main blog only)
mysql_query('create temporary table evo_temp ( ID integer(4) auto_increment, post_id integer(4), content mediumtext, primary key (ID) )');
//mysql_query('create table evo_temp ( ID integer(4) auto_increment, post_id integer(4), content mediumtext, primary key (ID) )');
$imgBlogs = mysql_query ("insert into evo_temp (post_id,content) select post_ID,post_content from $tableposts join $tablecategories on (cat_ID=post_main_cat_ID) where cat_blog_ID=7 and post_status='published' and post_content like '%<img%yyy%'");
// get total numbr of blogs w/images & randomly select one
$r = mysql_query ("select * from evo_temp"); // get everything from temp DB
$maxEntry = @mysql_num_rows($r); // count rows
$randomPost=mt_rand(1,$maxEntry); // choose random row
$r = mysql_query ("select ID,post_id,content from evo_temp where ID=$randomPost"); // pull data from random row
$randomContent = @mysql_fetch_row($r); // stuff it into a variable
// find # pics in random blog & randomly select one
// $numImgs = explode('<img class="yyy" ',"$randomContent[2]"); // chop entry right AFTER [<img class="yyy" ] ... [src="...]
$numImgs = explode('yyy" ',"$randomContent[2]"); // chop entry right AFTER [yyy" ] ... [src="...] (so can have multiple class names w/image) 10/05
$randomImg = mt_rand(1,count($numImgs)-1); // randomly choose an img chunk
$randomImg = $numImgs[$randomImg]; // stuff it into a variable
//echo $randomImg; // to see if blog section is correct
// extract pic location
$randomImg = substr($randomImg,strpos($randomImg,'yyy" src="')+10); // find position just beyond [src="]
$randomImg = substr($randomImg,0,strpos($randomImg,'"')); // extract everything between double quotes
//echo "path=";
//echo $randomImg; // to see if IMG path is correct [//randsco.com/_img/...]
// add the link and the image
echo '<a href="'.$baseurl.'/?p='.$randomContent[1].'"><img src="'.$randomImg.'" alt=" random image & link to blog entry " title=" Read the Journal Entry containing this photo " /></a>';
?>
It's pretty heavily commented, so you should be able to sort out what's what.
Hope this helps.
10 poopoo Aug 29, 2006 21:09
Hi, yeah I tried to add it to my main.php running 1.8.
That does not look like the kinda code I would need. I'm still learning....
11 stk Aug 29, 2006 23:31
Hmmm. OKAY.
I thought you wanted a random image from a previous post to show up in your sidebar?
While I know that you cannot simply cut-n-paste the above code and expect it to work (because it pulls from blog_ID #7 and yours is prolly different, it expects an image classname of "yyy" as an indicator to include the image and none of your images probably have that classname) ... it DOES do pretty much what you ask (plus more, as the image is even a link to the original post that it's from). ;)
Well ... if you want some advice or help, just shout.
Cheers,
12 poopoo Aug 30, 2006 00:24
thanks stk, Top Hack!! :p
I'll keep at it....
Do paste this code in the main.php where I want this picture to show up?
13 poopoo Aug 30, 2006 00:53
hey, that PCT looks amazing!
14 stk Aug 30, 2006 03:39
Yes, the code goes into your _main.php file for your skin. I wrap mine in a special DIV and then style it some.
The big thing to remember is that your blog_ID # will be different and that you need to add [style="yyy"] to your IMG tags ... specifically BEFORE the "src=" part, if they're to be considered as a possible random image.
First off; Wrong forum, should be in 'general questions'. (a mod will move it later).
And atm, this would be very hard to do.
Maybe in a year....