开发者

php - wrap post elements in <li> tags

I'm currently using a system for my portfolio where i add three images per project, which schould be inside an ul.

This works fine, but i need those img tags to be wrapped within li tags, and i have no clue how i should do this.

Take this:

<img src="img1.jpg"/>
<img src="img2.jpg"/>
<img src="img3.jpg"/>

Make this:

<li><img src="img1.jpg"/></li>
<li><img src="img2.jpg"/></li>
<li><img src="img3.jpg"/></li>

Thanks in advance!

Edit:

Sorry, here's more info for you guys:

I'm using Wordpress 3 as cms with custom post types. The output is done via wp's "the_content()", where i put my images.

I know i could use wp's html editor to wrap li tags around manually, the problem is that i wont be maintaining the site, so i want to make it easer for my coworkers.

This is why its outputting the img tags in a row, and i need to wrap those li tags around them. I've read something about "preg_replace", but i c开发者_Python百科ant seem to get it working.

EDIT: I've found the solution, sometimes the easiest way is the best:

$thecontent = get_the_content();
$thecontent_format = '<li>'.str_replace(array("\r","\n\n","\n"),array('',"\n","</li>\n<li>"),trim($thecontent,"\n\r")).'</li>';

wraps every img element with a li, and then

echo $thecontent_format;

Anyways, thanks for you participation!


I don't want to sound stupid or anything but if your trying to do this with PHP I am assuming that PHP is also creating the img tags for display.... in that case all you have to do is:

echo "<li>";

image tag generating code goes here

and than close it off with:

echo "</li>";

do this for every image tag that being created...

Is that what you were asking?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜