admin管理员组文章数量:1130349
I have a custom sidebar named "sidebar-events" that should only display posts in the "Events" category. I placed the following code in the sidebar. The header appears, but not the unordered list. In the source code there's nothing - no ul, no li. What am I doing wrong?
<div id="sidebar" class="widgets-area">
<h2>What's Going On</h2>
<?php
//what I will be looking for
$args = array(
"type" => post,
"posts_per_page" => 5,
"category_name" => "Events"
);
//create new query and pass the arguments
$recentEvents = new WP_Query($args);
if( $recentEvents->have_posts() ): ?>
<ul>
<?php while( $recentEvents->have_posts() ): $recentEvents->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
<?php endif; wp_reset_postdata();
?>
I have a custom sidebar named "sidebar-events" that should only display posts in the "Events" category. I placed the following code in the sidebar. The header appears, but not the unordered list. In the source code there's nothing - no ul, no li. What am I doing wrong?
<div id="sidebar" class="widgets-area">
<h2>What's Going On</h2>
<?php
//what I will be looking for
$args = array(
"type" => post,
"posts_per_page" => 5,
"category_name" => "Events"
);
//create new query and pass the arguments
$recentEvents = new WP_Query($args);
if( $recentEvents->have_posts() ): ?>
<ul>
<?php while( $recentEvents->have_posts() ): $recentEvents->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
<?php endif; wp_reset_postdata();
?>
Share
Improve this question
asked Dec 21, 2018 at 21:48
marilynnmarilynn
51 bronze badge
1 Answer
Reset to default 0You want to use post_type instead of just type and put apostrophes around your post type itself.
Instead of this:
$args = array(
"type" => post,
"posts_per_page" => 5,
"category_name" => "Events"
);
I would do this:
$args = array(
'post_type' => 'post',
'posts_per_page' => 5,
'category_name' => 'Events',
);
I have a custom sidebar named "sidebar-events" that should only display posts in the "Events" category. I placed the following code in the sidebar. The header appears, but not the unordered list. In the source code there's nothing - no ul, no li. What am I doing wrong?
<div id="sidebar" class="widgets-area">
<h2>What's Going On</h2>
<?php
//what I will be looking for
$args = array(
"type" => post,
"posts_per_page" => 5,
"category_name" => "Events"
);
//create new query and pass the arguments
$recentEvents = new WP_Query($args);
if( $recentEvents->have_posts() ): ?>
<ul>
<?php while( $recentEvents->have_posts() ): $recentEvents->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
<?php endif; wp_reset_postdata();
?>
I have a custom sidebar named "sidebar-events" that should only display posts in the "Events" category. I placed the following code in the sidebar. The header appears, but not the unordered list. In the source code there's nothing - no ul, no li. What am I doing wrong?
<div id="sidebar" class="widgets-area">
<h2>What's Going On</h2>
<?php
//what I will be looking for
$args = array(
"type" => post,
"posts_per_page" => 5,
"category_name" => "Events"
);
//create new query and pass the arguments
$recentEvents = new WP_Query($args);
if( $recentEvents->have_posts() ): ?>
<ul>
<?php while( $recentEvents->have_posts() ): $recentEvents->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
<?php endif; wp_reset_postdata();
?>
Share
Improve this question
asked Dec 21, 2018 at 21:48
marilynnmarilynn
51 bronze badge
1 Answer
Reset to default 0You want to use post_type instead of just type and put apostrophes around your post type itself.
Instead of this:
$args = array(
"type" => post,
"posts_per_page" => 5,
"category_name" => "Events"
);
I would do this:
$args = array(
'post_type' => 'post',
'posts_per_page' => 5,
'category_name' => 'Events',
);
本文标签: unordered list loop not showing up in sidebar
版权声明:本文标题:unordered list loop not showing up in sidebar 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749076995a2312457.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论