perloader

有时候,你可能想在小工具中运行PHP代码,可以使用插件实现次能功能,也可以自己动手写代码实现此功能,将下面的代码添加到主题文件夹下的 functions.php文件中,你的PHP代码立即起作用了。

// 运行php代码
add_filter('widget_text','execute_php',100);
function execute_php($html){
     if(strpos($html,"<"."?php")!==false){
          ob_start();
          eval("?".">".$html);
          $html=ob_get_contents();
          ob_end_clean();
     }
     return $html;
}

好了,现在你的侧边栏小工具中的PHP代码魔力般的工作了,就是这么简单.

 

列出某个分类下的所有文章

<?php query_posts('cat=34888&posts_per_page=100'); while(have_posts()): the_post(); ?>   
   <li><a href="<?php the_permalink(); ?>" target="_blank"><?php the_title();?></a></li>   
<?php endwhile; wp_reset_query(); ?>

 

xyz