Php 在WordPress主题中循环,仅显示标记的文章,don';行不通
我是PHP和WordPress领域的新手,在创建一个只显示具有特定标记的帖子的循环时遇到了问题 在主页中,我将创建一个循环,仅显示设置了特定标记的文章,因此我为wordpress实现了以下PHP循环:Php 在WordPress主题中循环,仅显示标记的文章,don';行不通,php,content-management-system,wordpress-theming,wordpress,Php,Content Management System,Wordpress Theming,Wordpress,我是PHP和WordPress领域的新手,在创建一个只显示具有特定标记的帖子的循环时遇到了问题 在主页中,我将创建一个循环,仅显示设置了特定标记的文章,因此我为wordpress实现了以下PHP循环: <div id="column2"> <?php query_posts( 'tag=sasha' ); if(have_posts()): while (have_
<div id="column2">
<?php
query_posts( 'tag=sasha' );
if(have_posts()):
while (have_posts()): the_post();
?>
<?php endwhile; else: ?>
<?php endif; ?>
</div> <!-- end column2 -->
我有一篇文章,我在其中贴了一个标签:萨沙
问题是不工作,我的Column2div仍然是空的。为什么?你能帮我吗
Tnx
Andrea以下是使用
WP\u QUERY
时它的外观:
$args = array('tag' => 'sasha');
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) :
$the_query->the_post();
echo '<div>' . get_the_title() . '</div>';
the_content();
endwhile;
wp_reset_postdata();
$args=array('tag'=>'sasha');
$thew_query=newwp_query($args);
while($the\u query->have\u posts()):
$the_query->the_post();
回显“”。获取“标题()”;
_内容();
结束时;
wp_reset_postdata();
请不要使用query\u posts使用wp\u query而不是在没有标记的情况下尝试,也要发布循环位于page.php或single.php中的代码,等等,这是您说的“out the tag”的意思吗?没有标记,对不起。我的意思是,如果不以这种方式使用sashappassessing no tag,不要传递标记以查看它是否工作:$args=array();(在index.php页面中)列仍然是空的!!!:-/Ohhh是的,这个错误是我的,因为我在前面的代码片段中留下了if语句(不是你的!!!)哈哈