SimplePortal

Customization => Custom Coding => Topic started by: saurabh1938 on January 07, 2015, 01:59:10 PM

Title: Custom PHP block to show articles Topic with first Image?
Post by: saurabh1938 on January 07, 2015, 01:59:10 PM
Hi All,

First of all I want to thank the community for giving such a wonderful support and with the help of it I was able to create a website with minimum coding knowledge.

I am searching for a custom php block in which I can show article Topic name and a first image of article shown adjacent to Topic name.

Can this be done?

Thanks in advance
Title: Re: Custom PHP block to show articles Topic with first Image?
Post by: saurabh1938 on January 11, 2015, 06:48:10 PM
Anybody?
Title: Re: Custom PHP block to show articles Topic with first Image?
Post by: ataru on April 28, 2015, 04:16:58 AM
i did somethin similar last week


i used to modify sp_articles function to catch and remove all images and first URL from article body

Code: [Select]
$corpodellarticolo = $article['msg']['body'];
$pattern = "/\[img(.*?)]([^\[]+)\[\/img]/i";
preg_match_all($pattern, $article['msg']['body'], $matches, PREG_SET_ORDER);
foreach ($matches as $val) {
$imgs[] = $val[2];
$corpodellarticolo = str_replace($val[0],"",$corpodellarticolo);
}

$pattern = "/\[url(.*?)]([^\[]+)\[\/url]/i";
preg_match_all($pattern, $article['msg']['body'], $matches, PREG_SET_ORDER);
foreach ($matches as $val) {
$urls[] = $val[0];
$corpodellarticolo = str_replace($val[0],"",$corpodellarticolo);
}
// trim all double breaks
for ($spazi = 0; $spazi < 10; $spazi++) {
$corpodellarticolo = str_replace("<br /><br />","<br />", $corpodellarticolo);
}
$article['msg']['body'] = $corpodellarticolo;

then I put catched URL and first image in the very first lines of body and let function go on

Code: [Select]
if ( isset($imgs) ) {
$article['msg']['body'] = '[img]'.$imgs[0].'[/img]<br />'.$article['msg']['body'];
unset($imgs);
}
if ( isset($urls) ) {
$article['msg']['body'] = $urls[0].'<br />'.$article['msg']['body'];
unset($urls);
}
Title: Re: Custom PHP block to show articles Topic with first Image?
Post by: velorooms on April 30, 2015, 12:31:34 PM
which file and where did you put these edits?
Title: Re: Custom PHP block to show articles Topic with first Image?
Post by: ataru on May 04, 2015, 07:26:19 AM
which file and where did you put these edits?

it works in Sources/PortalBlocks.php

I used to call a custom php block and put in it the modified content of sp_articles() function defining my own vars and parameters
Title: Re: Custom PHP block to show articles Topic with first Image?
Post by: saurabh1938 on July 09, 2015, 07:36:25 AM
too much rocket science for me, can you show me a demo and steps to do it?
Title: Re: Custom PHP block to show articles Topic with first Image?
Post by: ataru on September 09, 2015, 09:19:17 AM
look here

http://simpleportal.net/index.php?topic=14099.msg70208#msg70208
SimplePortal 2.3.8 © 2008-2024, SimplePortal