Focus on cloud service provider activities
Notes on website operation and maintenance

Several common Typecho article calling codes

When we re develop the Typecho program theme, we will use more article calls, such as the call of the latest article, the latest article, and the popular article. Here I sort out the code as follows.

Latest articles:

 <?php $this->widget('Widget_Contents_Post_Recent')->to($post); ?> <?php while($post->next()): ?> <a href=”<? php $post->permalink(); ?>”  title=”<? php $post->title(); ?>”> <?php $post->title(25, '…'); ?></ a> <?php endwhile; ?>

Popular article calls:

 //Popular articles call by laozuo.org function getHotComments($limit = 10){ $db = Typecho_Db:: get(); $result = $db->fetchAll($db->select()->from('table.contents') ->where('status = ?','publish') ->where('type = ?', 'post') ->Where ('created<=unix_timestamp (now()) ','post')//Add this sentence to avoid early exposure of articles that have not reached the time limit ->limit($limit) ->order('commentsNum', Typecho_Db::SORT_DESC) ); if($result){ foreach($result as $val){             $val = Typecho_Widget:: widget('Widget_Abstract_Contents')->push($val); $post_title = htmlspecialchars($val['title']); $permalink = $val['permalink']; echo '<li><a href="'.$permalink.'" title="'.$post_title.'" target="_blank">'.$post_title.'</a></li>';         } } }

Call:

 <?php getHotComments('10');?>

Related article calls:

 <?php $this->related(5)->to($relatedPosts); ?> <ul> <?php while ($relatedPosts->next()): ?> <li><a href="<?php%20$relatedPosts->permalink();%20?>" title="<?php $relatedPosts->title(); ?>"><? php $relatedPosts->title(); ?></ a></li> <?php endwhile; ?> </ul>

 

Vote for you
Domain name host preferential information push QQ group: six hundred and twenty-seven million seven hundred and seventy-five thousand four hundred and seventy-seven Get preferential promotion from merchants.
Like( zero )
Do not reprint without permission: Lao Zuo's Notes » Several common Typecho article calling codes