Post 如何从wordpress的tinymce编辑器中获取图像?
我有代码来显示特色图片显示在帖子中,还知道获取特色图片路径url。但我不知道如何获取插入的tinymce图像的url路径。插入的图像在帖子上正确显示,但我不知道如何获取图像的相应url。这是我使用的代码Post 如何从wordpress的tinymce编辑器中获取图像?,post,tinymce,wordpress,Post,Tinymce,Wordpress,我有代码来显示特色图片显示在帖子中,还知道获取特色图片路径url。但我不知道如何获取插入的tinymce图像的url路径。插入的图像在帖子上正确显示,但我不知道如何获取图像的相应url。这是我使用的代码 function bdw_get_images() { // Get the post ID $iPostID = $post->ID; // Get images for this post $arrImages =& get_children
function bdw_get_images() {
// Get the post ID
$iPostID = $post->ID;
// Get images for this post
$arrImages =& get_children('post_type=attachment&post_mime_type=image&post_parent=' . $iPostID );
// If images exist for this page
if($arrImages) {
// Get array keys representing attached image numbers
$arrKeys = array_keys($arrImages);
/******BEGIN BUBBLE SORT BY MENU ORDER************
// Put all image objects into new array with standard numeric keys (new array only needed while we sort the keys)
foreach($arrImages as $oImage) {
$arrNewImages[] = $oImage;
}
// Bubble sort image object array by menu_order TODO: Turn this into std "sort-by" function in functions.php
for($i = 0; $i < sizeof($arrNewImages) - 1; $i++) {
for($j = 0; $j < sizeof($arrNewImages) - 1; $j++) {
if((int)$arrNewImages[$j]->menu_order > (int)$arrNewImages[$j + 1]->menu_order) {
$oTemp = $arrNewImages[$j];
$arrNewImages[$j] = $arrNewImages[$j + 1];
$arrNewImages[$j + 1] = $oTemp;
}
}
}
// Reset arrKeys array
$arrKeys = array();
// Replace arrKeys with newly sorted object ids
foreach($arrNewImages as $oNewImage) {
$arrKeys[] = $oNewImage->ID;
}
******END BUBBLE SORT BY MENU ORDER**************/
// Get the first image attachment
$iNum = $arrKeys[0];
// Get the thumbnail url for the attachment
$sThumbUrl = wp_get_attachment_thumb_url($iNum);
// UNCOMMENT THIS IF YOU WANT THE FULL SIZE IMAGE INSTEAD OF THE THUMBNAIL
//$sImageUrl = wp_get_attachment_url($iNum);
// Build the <img> string
$sImgString = '<a href="' . get_permalink() . '">' .
'<img src="' . $sThumbUrl . '" width="150" height="150" alt="Thumbnail Image" title="Thumbnail Image" />' .
'</a>';
// Print the image
echo $sImgString;
}
}
函数bdw\u get\u images(){
//获取邮政ID
$iPostID=$post->ID;
//获取此帖子的图片
$arrImages=&get_children('post_type=attachment&post_mime_type=image&post_parent='。$iPostID);
//如果此页面存在图像
如果($ARR图像){
//获取表示附加图像编号的数组键
$arrKeys=数组_键($arrKeys);
/******按菜单顺序开始气泡排序************
//使用标准数字键将所有图像对象放入新数组(仅在对键排序时需要新数组)
foreach($arr图像为$oImage){
$arrNewImages[]=$oImage;
}
//气泡按菜单对图像对象数组排序\u顺序TODO:将其转换为functions.php中的std“sort by”函数
对于($i=0;$i菜单顺序>(int)$arrNewImages[$j+1]->菜单顺序){
$oTemp=$arrNewImages[$j];
$arrNewImages[$j]=$arrNewImages[$j+1];
$arrNewImages[$j+1]=$oTemp;
}
}
}
//重置arrKeys数组
$arrKeys=array();
//用新排序的对象ID替换ARRKEY
foreach($arrNewImages作为$oNewImage){
$arrKeys[]=$oNewImage->ID;
}
******按菜单顺序结束冒泡排序**************/
//获取第一个图像附件
$iNum=$arrKeys[0];
//获取附件的缩略图url
$sThumbUrl=wp\u get\u attachment\u thumb\u url($iNum);
//如果希望使用全尺寸图像而不是缩略图,请取消对此的注释
//$sImageUrl=wp\u get\u attachment\u url($iNum);
//构建字符串
$sImgString='';
//打印图像
echo$sImgString;
}
}
有人建议我在wordpress插入的tinymce编辑器中获取图像url
谢谢,
vickypreg\u match\u all('/
当您在wordpress循环中提取文章内容,甚至通过get_post获取内容时,使用上述内容将为您提供tinymce编辑器文章内容中所有图像的url
$post_details=get_post($post->ID);
preg_match_all( '/<img .*?(?=src)src=\"([^\"]+)\"/si', $post_details->post_content, $allpics );
foreach($allpics[1] as $pics){
echo $pics;
}
$post\u details=get\u post($post->ID);
预匹配全部('/post内容,$allpics);
foreach($allpics[1]作为$pics){
echo$pics;
}
$post_details=get_post($post->ID);
preg_match_all( '/<img .*?(?=src)src=\"([^\"]+)\"/si', $post_details->post_content, $allpics );
foreach($allpics[1] as $pics){
echo $pics;
}