Hi allemaal,
Ik ben bezig met een functie waardoor het onderstaande script automatisch de eerste afbeelding uit een post laadt. (wordpress)
Zoals je hierboven ziet kan de afbeelding variabel zijn maar ik wil dat de afbeelding vaste formaten heeft.PHP Code:
function getImage($num) {
global $more;
$more = 1;
$link = get_permalink();
$content = get_the_content();
$count = substr_count($content, '<img');
$start = 0;
for($i=1;$i<=$count;$i++) {
$imgBeg = strpos($content, '<img', $start);
$post = substr($content, $imgBeg);
$postOutput = preg_replace('/width="([0-9]*)" height="([0-9]*)"/', '',$postOutput);;
$imgEnd = strpos($post, '>');
$postOutput = substr($post, 0, $imgEnd+1);
$image[$i] = $postOutput;
$start=$imgEnd+1;
}
if(stristr($image[$num],'<img')) { echo '<a href="'.$link.'">'.$image[$num]."</a>"; }
$more = 0;
}
Heeft iemand een oplossing die ik kan aanpassen in het bovenstaande script? Het is wel belangrijk dat ik met het bovenstaande script kan blijven werken.
- Probleem met image (php / wordpress)
-
30-03-2011, 16:56 #1
- Berichten
- 1.735
- Lid sinds
- 17 Jaar
Probleem met image (php / wordpress)
-
-
30-03-2011, 17:34 #2
- Berichten
- 980
- Lid sinds
- 17 Jaar
Re: Probleem met image (php / wordpress)
Dit past de hoogte/breedte aan voor plaatjes die deze bepaling in hun html hebben staan. Ik weet niet precies of je dat wilt en of wordpress die informatie standaard meelevert.
PHP Code:function getImage($num) {
global $more;
$more = 1;
$link = get_permalink();
$content = get_the_content();
$count = substr_count($content, '<img');
$start = 0;
for($i=1;$i<=$count;$i++) {
$imgBeg = strpos($content, '<img', $start);
$post = substr($content, $imgBeg);
$postOutput = preg_replace('/width="([0-9]*)" height="([0-9]*)"/', 'width="250px" height="250px"',$postOutput);
$imgEnd = strpos($post, '>');
$postOutput = substr($post, 0, $imgEnd+1);
$image[$i] = $postOutput;
$start=$imgEnd+1;
}
if(stristr($image[$num],'<img')) { echo '<a href="'.$link.'">'.$image[$num]."</a>"; }
$more = 0;
}
Laatst aangepast door Daniel Klabbers : 30-03-2011 om 17:51
-
30-03-2011, 18:58 #3
- Berichten
- 1.735
- Lid sinds
- 17 Jaar
Re: Probleem met image (php / wordpress)
Hi Daniel,
Deze code gebruik ik voor de output:
<?php getImage('1'); ?>
-
30-03-2011, 19:07 #4
- Berichten
- 980
- Lid sinds
- 17 Jaar
Re: Probleem met image (php / wordpress)
Vage functie trouwens..
PHP Code:function getImage($num) {
global $more;
$more = 1;
$link = get_permalink();
$content = get_the_content();
$count = substr_count($content, '<img');
$start = 0;
for($i=1;$i<=$count;$i++) {
$imgBeg = strpos($content, '<img', $start);
$post = substr($content, $imgBeg);
$postOutput = preg_replace('/width="([0-9]*)" height="([0-9]*)"/', '',$postOutput);
$imgEnd = strpos($post, '>');
$postOutput = substr($post, 0, $imgEnd+1);
$image[$i] = $postOutput;
$start=$imgEnd+1;
}
if(stristr($image[$num],'<img')) { echo '<a href="'.$link.'" width="250px" height="250px">'.$image[$num]."</a>"; }
$more = 0;
}
-
03-04-2011, 10:05 #5
- Berichten
- 1.735
- Lid sinds
- 17 Jaar
Re: Probleem met image (php / wordpress)
Ik heb je code geprobeerd alleen weergeeft nog steeds de afbeeldingen in origineel formaat.
-
03-04-2011, 10:18 #6
- Berichten
- 980
- Lid sinds
- 17 Jaar
Re: Probleem met image (php / wordpress)
Voeg me even toe (zie profiel), zodat ik er even fatsoenlijk naar kan kijken. Want dit schiet natuurlijk niet op.
Plaats een
- + Advertentie
- + Onderwerp
Marktplaats
Webmasterforum
- Websites algemeen
- Sitechecks
- Marketing
- Domeinen algemeen
- Waardebepaling
- CMS
- Wordpress
- Joomla
- Magento
- Google algemeen
- SEO
- Analytics
- Adsense
- Adwords
- HTML / XHTML
- CSS
- Programmeren
- PHP
- Javascript
- JQuery
- MySQL
- Ondernemen algemeen
- Belastingen
- Juridisch
- Grafisch ontwerp
- Hosting Algemeen
- Hardware Info
- Offtopic