Php 简单的Wordpress循环结果完全错误,充满了中断和<;p>;元素
我试图通过我的wordpress帖子做一个简单的循环,但是当它输出整个东西时,循环会把它放在任何地方,而不是我说的地方,它应该放在哪里。例如,循环添加了中断和,但它们不在我的帖子中。我曾经有过这个问题,但我不知道我做了什么来克服这个问题 我的循环:Php 简单的Wordpress循环结果完全错误,充满了中断和<;p>;元素,php,wordpress,loops,while-loop,Php,Wordpress,Loops,While Loop,我试图通过我的wordpress帖子做一个简单的循环,但是当它输出整个东西时,循环会把它放在任何地方,而不是我说的地方,它应该放在哪里。例如,循环添加了中断和,但它们不在我的帖子中。我曾经有过这个问题,但我不知道我做了什么来克服这个问题 我的循环: <?php $args = array( 'post_type' => 'post', 'posts_per_page' => 4 ); $loop = new WP_Query($args); if ($loop
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 4
);
$loop = new WP_Query($args);
if ($loop->have_posts()) {
while ($loop->have_posts()) : $loop->the_post();
$post_id = get_the_ID();
$content = the_content();
$headline = get_post_meta($post_id, 'headline', true);
$subtitle = get_post_meta($post_id, 'untertitel', true);
$class = wp_get_post_terms( $post_id, 'post_tag', $termsargs );
$bgimage = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
echo '<section class="section zutaten '.$class[0].'" style="background-image: url('.$bgimage.')">';
echo '<article class="zutaten-beschreibung">';
echo '<header>';
echo '<h2><strong>'.$headline.'</strong></h2>';
echo '<h3>'.$subtitle.'</h3>';
echo '<div class="zutaten-beschreibung-content">';
echo $content;
echo '</div>';
echo '</header>';
echo '</article>';
echo '</section>';
endwhile;
} else {
echo __('Fehler!');
}
wp_reset_postdata();
?>
结果:
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 4
);
$loop = new WP_Query($args);
if ($loop->have_posts()) {
while ($loop->have_posts()) : $loop->the_post();
$post_id = get_the_ID();
$content = the_content();
$headline = get_post_meta($post_id, 'headline', true);
$subtitle = get_post_meta($post_id, 'untertitel', true);
$class = wp_get_post_terms( $post_id, 'post_tag', $termsargs );
$bgimage = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
echo '<section class="section zutaten '.$class[0].'" style="background-image: url('.$bgimage.')">';
echo '<article class="zutaten-beschreibung">';
echo '<header>';
echo '<h2><strong>'.$headline.'</strong></h2>';
echo '<h3>'.$subtitle.'</h3>';
echo '<div class="zutaten-beschreibung-content">';
echo $content;
echo '</div>';
echo '</header>';
echo '</article>';
echo '</section>';
endwhile;
} else {
echo __('Fehler!');
}
wp_reset_postdata();
?>
这里出了什么问题?函数
内容()
正在打印数据。您应该使用获取内容()
。我可以看出这里出了什么问题。echo$内容代码>行正在打印不正确的HTML。我知道这一点,因为你在标题中说,有许多
标签不应该放在那里;并且您没有(明显地)在这段代码中打印任何
标记
调查此方法返回的内容:$content=the_content()代码>应该可以了。欢迎来到wordpress…thx mate。我以前试过,但什么也没发生。现在,在回显$class[0]变量时发生了另一个错误。控制台显示:“可捕获的致命错误-类stdClass的对象无法转换为字符串”。我怎么能输出这个东西?嗯。。。这似乎是一个数组。我不确定PHP中的覆盖,但是,您应该有一个包含stdClass
类的文件。在代码中找到它,然后搜索返回字符串或整数的方法。可能如下所示的行:echo$class[0]代码>可能如下所示:echo$class[0].print()代码>数组中的对象:)这个为我做:$class[0]->name