文章摘要
这篇文章展示了如何利用WordPress通过PHP代码实现文章展示功能。代码中首先加载了必要的功能,然后通过`query_posts`函数加载最新文章,或通过`get_most_viewed`函数获取热门文章。生成的内容以HTML表格形式显示,每次循环展示一篇新文章,并通过`the_permalink()`函数自动生成链接。代码结构简单,适合快速实现文章展示功能。
<?php // Include WordPress define('WP_USE_THEMES', false); require('./wp-load.php'); query_posts('showposts=5'); //这个调用最新文章,如果是热门文章的话则改为get_most_viewed("post",10),前提是你的主题安装了热门文章插件,而且此方法可以接受几乎wp-kit-cn所有代码。 ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <?php while (have_posts()): the_post(); ?> <tr><td height="23">· 【新上源码】 <a href="<?php the_permalink(); ?>" target="_blank"><b><?php echo mb_strimwidth(strip_tags(apply_filters('the_title', $post->post_title)), 0, 50," "); ?></b></a></td></tr> <?php endwhile; ?> </table>
目录建立php文件把代码粘贴进去就可以了。在其他地方随意调用自身内容