脚本宝典收集整理的这篇文章主要介绍了php – WordPress动态自定义菜单无法显示正确的结果,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_404_8@
这是我的代码:(我想要的帖子的类别ID:4)@H_404_8@
@H_404_8@
<div class="col-md-4 enigma-sidebar"> <?PHP if ( is_active_sidebar( 'sidebar-Primary' ) ) { dynamic_sidebar( 'sidebar-PRimary' ); } else { $args = array( 'before_widget' => '<div class="enigma_sidebar_widget">','after_widget' => '</div>','before_tITle' => '<div class="enigma_sidebar_widget_title"><h2>','after_title' => '</h2></div>' ); the_widget('WP_Widget_Archives',null,$args); } ?> <?PHP /*Menu LooP*/ function menu1_loop() { global $post; $args = array( 'tyPE' => 'post','orderby' => 'date','order' => 'ASC','hide_empty' => 1,'include' => '4','number' => '','taxonomy' => 'category',); $categories = get_categories( $args ); foreach($categories as $category) { // WP_Query arguments $args = array ( 'category_name' => 'cat-htML','order' => 'ASC','orderby' => 'date',); // The Query $query = new WP_Query( $args ); //Loop if ( $query->have_posts() ) { /*echo "<div>"; */ while ( $query->have_posts() ) { $post.the_permalink(); $post.the_title(); /*echo "<li><a href=".the_permalink().">".the_title()."</a></li>";*/ $query->the_post(); } /*echo "</div>";*/ } // ReStore Original post data wp_reset_postdata(); } } ?> <!-- # Added by Aryansh Malviya(ARVIS APPS) on Saturday,December 12th,2015 # Added to make a custom menu for specific task // begins --> <?PHP wp_nav_menu( array( 'theme_location' => 'html-menu','container_class' => 'enigma_sidebar_widget' ) /*.menu1_loop()*/ ); ?> <?PHP wp_nav_menu( array( 'theme_location' => 'PHP-menu','container_class' => 'enigma_sidebar_widget' ) ); ?> <!-- // ends --> </div>
这段代码没有做我认为应该做的事情,这里有一张图片显示了这个结果:
@H_404_8@@H_404_8@
@H_404_8@
function getPostsByCategoryID($categoryID) { $args = array( 'posts_per_page' => -1,'offset' => 0,'category' => $categoryID,'orderby' => 'date','order' => 'ASC','post_type' => 'post','post_status' => 'publish',); $allposts = get_posts( $args ); foreach ( $allposts as $p ): echo '<li><a href="'. get_permalink($p->ID) . '">' . get_the_title($p->ID) . '</a></li>'; enDForeach; }
像这样在你的侧边栏或任何你想要的地方使用它:@H_404_8@
@H_404_8@
<?PHP getPostsByCategoryID(HERE_THE_CATEGORY_ID); ?>
例如:@H_404_8@
@H_404_8@
<?PHP getPostsByCategoryID(4); ?>
以上是脚本宝典为你收集整理的php – WordPress动态自定义菜单无法显示正确的结果全部内容,希望文章能够帮你解决php – WordPress动态自定义菜单无法显示正确的结果所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。