今天追格小程序小编给大家分享WordPress文章按浏览量排序的方法,适用于调用分类的热门文章,本文仅适合具备一定编程基础的人进行二次开发。
1、展示浏览量的示例代码
在WordPress主题的functions.php文件至下方的“?>”前,加入以下PHP代码即可。
function themetuts_record_visitors(){ if (is_singular()) {
global $post; $post_ID = $post->ID; if($post_ID) { $post_views = (int)get_post_meta($post_ID, 'views', true); if(!update_post_meta($post_ID, 'views', ($post_views+1))) { add_post_meta($post_ID, 'views', 1, true); } } } } add_action('wp_head', 'themetuts_record_visitors'); function themetuts_the_view($before = '', $after = '', $echo = 1) { global $post; $post_ID = $post->ID; $views = (int)get_post_meta($post_ID, 'views', true); if ($echo) echo $before, number_format($views), $after;
else return $views; }
2、文章页面调用本标签
<?php themetuts_the_view(); ?>
3、按浏览量排序示例代码
<?php$args=array('meta_key' => 'views','orderby' => 'meta_value','order' => 'date');query_posts($args);while ( have_posts() ) : the_post();?>
<li>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php if(has_post_thumbnail()) {the_post_thumbnail('post');} else { ?><img src="<?php echo get_template_directory_uri();?>/images/thumbnail/<?php echo rand(1,6);?>.png" alt="<?php the_title(); ?>" /><? } ?>
<span class="itemtit"><?php the_title(); ?></span>
<span class="itempoint clr">
<span class="price"><?php the_field('price'); ?></span>
<span class="hots"><span class="fa fa-sun-o"></span><?php themetuts_the_view(); ?></span>
</span>
</a>
</li><?php endwhile;wp_reset_query();?>
-
追格小程序建圈、发帖、商城发布商品报错 Warning: Undefined variable $result in追格小程序建圈、发帖、商城发布商品报错Warning: Undefined variable $result in /www/wwwroot/xly/wp-content/plugins/zhuige-xcx/public/class-zhuige-xcx-public.php on line 159
-
【重要通知】追格小程序更新提示因uni组件更新,追格小程序部分模块样式出现异常。我们已定位问题并正优化中,给您带来不便敬请谅解。感谢支持与理解!追格团队将持续努力,优化产品体验,期待更快与您相见。
-
微信小程序打开任意公众号文章 wx.openOfficialAccountArticlewx.openOfficialAccountArticle是微信小程序通过小程序打开任意公众号文章api,不包括临时链接等异常状态下的公众号文章,必须有点击行为才能调用成功。
-
Loco Translate 一款专为WordPress设计的翻译插件WordPress Loco Translate是一款专为WordPress用户设计的翻译插件,它简化了主题和插件的多语言翻译过程。
-
追格小程序V2.5.0更新发布追格小程序V2.5.0版本的更新,我们没给大家添太多新花样,主要是把“内功”练好了。我们认真检查了上一版里那些组件之间的小摩擦,一点点地调整、优化,搞定了超过40多个小地方。这样一来,小程序跑起来就更顺畅了,大家用起来也会感觉更舒服、更顺手。这次虽然没大张旗鼓,但确实是让产品站得更稳、更可靠了。
-
WordPress后台待审文章显示气泡提示的方法之前小编分享过一篇《WordPress 后台菜单添加 badge-红点提示(气泡通知)》的文章,今天我简单说说待审文章(为全部文章类型显示待审角标提示)的气泡提示如何操作。
暂无评论,抢个沙发...