7moHi, 我有joomla 3,我想将文章的第一张图片设置为类别博客替代中的介绍图片。 我有一个插件,可抓取文章的第一张图片并将其设置在og图片元标记中。我认为我们可以将这个功能用于我的问题。 这是插件的代码
WebDriver webdriver = new ChromeDriver();
此时,我想在覆盖页面中插入结果
// Image
$pictures = '';
if (isset($row->images)) {
//$pictures = json_decode($row->images);
$pictures = (is_string($row->images) ? json_decode($row->images) : $row->images);
}
$imgSet = 0;
if ($this->params->get('image'.$suffix, '') != '' && $parameterImage == 1) {
$this->renderTag('og:image', $this->setImage($this->params->get('image'.$suffix, '')), $type);
$imgSet = 1;
} else if ($thisImg != ''){
$this->renderTag('og:image', $this->setImage($thisImg), $type);
$imgSet = 1;
} else if (isset($pictures->{'image_intro'}) && $pictures->{'image_intro'} != '') {
$this->renderTag('og:image', $this->setImage($pictures->{'image_intro'}), $type);
$imgSet = 1;
} else if (isset($pictures->{'image_fulltext'}) && $pictures->{'image_fulltext'} != '') {
$this->renderTag('og:image', $this->setImage($pictures->{'image_fulltext'}), $type);
$imgSet = 1;
} else {
// Try to find image in article
$fulltext = '';
if (isset($row->fulltext) && $row->fulltext != '') {
$fulltext = $row->fulltext;
}
$introtext = '';
if (isset($row->introtext) && $row->introtext != '') {
$introtext = $row->introtext;
}
$content = $introtext . $fulltext;
preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $content, $src);
if (isset($src[1]) && $src[1] != '') {
$this->renderTag('og:image', $this->setImage($src[1]), $type);
//$this->renderTag('og:image', JURI::base(false).$src[1], $type);
$imgSet = 1;
}
// Try to find image in images/phocaopengraph folder
if ($imgSet == 0) {
if (isset($row->id) && (int)$row->id > 0) {
jimport( 'joomla.filesystem.file' );
$imgPath = '';
$path = JPATH_ROOT . '/images/phocaopengraph/';
if (JFile::exists($path . '/' . (int)$row->id.'.jpg')) {
$imgPath = 'images/phocaopengraph/'.(int)$row->id.'.jpg';
} else if (JFile::exists($path . '/' . (int)$row->id.'.png')) {
$imgPath = 'images/phocaopengraph/'.(int)$row->id.'.png';
} else if (JFile::exists($path . '/' . (int)$row->id.'.gif')) {
$imgPath = 'images/phocaopengraph/'.(int)$row->id.'.gif';
}
if ($imgPath != '') {
$this->renderTag('og:image', $this->setImage($imgPath), $type);
$imgSet = 1;
}
}
}
}
// If still image not set and parameter Image is set as last, then try to add the parameter image
if ($imgSet == 0 && $this->params->get('image'.$suffix, '') != '' && $parameterImage == 0) {
$this->renderTag('og:image', $this->setImage($this->params->get('image'.$suffix, '')), $type);
}
// END IMAGE
但是我不能出于我的目的修改代码。
在覆盖eof模板中,我还发现了 <div class="image-intro">
<?php echo JLayoutHelper::render('joomla.content.intro_image', $this->item); ?>
<div>
该认为显示全文。
我可以抓取文章的第一张图片并插入介绍性文字吗?
答案 0 :(得分:0)
$texthtml=$this->item->text;
preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $texthtml, $image);
$imgkk=$image['src'];
echo '<img src="' . $imgkk. ' ">'
?>
我解决了!