开发者

I need assistance with my wordpress theme

开发者 https://www.devze.com 2023-04-12 07:54 出处:网络
<?php $i = 0; $page = get_the_content(); $doc=new DOMDocument(); $doc->loadHTML($page); $xml=simplexml_import_dom($doc);
<?php
$i = 0;
$page = get_the_content();
$doc=new DOMDocument();
$doc->loadHTML($page);
$xml=simplexml_import_dom($doc);
$i开发者_开发问答mages=$xml->xpath('//img');
foreach ($images as $img) {
list($width, $height, $type, $attr) = getimagesize($img['src']);

if ($height > 149 ) {  
    echo '<img src="' . $img['src'] . '" alt=" ' . $img['alt'] . ' - funny and hot pictures" title=" ' . $img['title'] . ' - funny fail picture dump" onerror=\'this.style.display="none" \'><br>';
$i++;
if ($i == 3 ) { break;}
}
else
{
// don't display
}
}
?>

I replaced the "<?php the_content(); ?>" piece of code with the one above. It's supposed to strip out all of the text in my post and just leave the images which it does nicely. But when I embed a video the php breaks. How would I allow posts to show youtube videos?


You should look into using custom fields:

http://codex.wordpress.org/Custom_Fields

There is a great plugin that creates good admin control panels for them too:

http://wordpress.org/extend/plugins/advanced-custom-fields/

You could use a custom field to specifically put a video into the page.

Is there a particular reason you want to strip the text out of the post? - e.g. could you just not put text in the post at all? - or could the text be put into the excerpt instead, or into a custom field so that you don't have to over complicate the output code?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号