【发布时间】:2015-07-21 08:49:41
【问题描述】:
我正在查看 WordPress 博客,并试图弄清楚在显示内容时如何分别显示图像和文本。我想这样做的原因是因为我想创建一个自定义布局,并且我需要能够在不同时抓取所有文本的情况下移动图像。有谁知道如何做到这一点?
我已经得到的示例:(已更新)
<?php
require('blog/wp-blog-header.php');
?>
<?php
$args = array( 'numberposts' => 2, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
echo '<ul id="latest_posts">';
foreach
($postslist as $post) : setup_postdata($post);
echo get_content_without_tag( apply_filters( 'the_content', get_the_content() ), 'a' );
$image = get_tag_without_text( apply_filters( 'the_content', get_the_content() ), 'a' );
?>
<li>
<strong>
<?php the_date(); ?>
</strong>
<br />
<a href="<?php the_permalink(); ?>" title="<?php the_title();?>"> <?php the_title(); ?></a>
<p>
<?php echo $image[0]; ?>
</p>
</li>
<?php endforeach; ?>
</ul>
错误:
警告:DOMDocument::saveHTML() 需要 0 个参数,1 个给定 在 /hsphere/local/home/poulaum/isosec.co.uk/blog/wp-includes/functions.php 在线 4874
和图片显示上述代码显示的内容:
【问题讨论】:
-
您可以使用正则表达式来捕获图像标签,但您不会使用
CSS更改布局吗? -
@BenPearlKahan 我将使用 CSS 是的,但我希望在使用 CSS 之前将图像放置在某个元素中。这就是为什么我想把它从文本中拆分出来