Daily Lucky Numbers:
8
11
19
29
40
42

how to do manual limit 4

Started by replikacep, January 23, 2019, 01:13:07 PM

Previous topic - Next topic

replikacep

smf 2.1

Number of recent posts to display on board index  :  how to do manual limit 4

I need to add a fixed limit of 4

need to work independently from the theme panel

/**
 * This actually displays the board index
 */
function template_main()
{
 global $context, $txt, $scripturl, $memberContext;
echo '<div class="row text-center">';
 /* Each post in latest_posts has:
 board (with an id, name, and link.), topic (the topic's id.), poster (with id, name, and link.),
 subject, short_subject (shortened with...), time, link, and href. */
 foreach ($context['latest_posts'] as $post){
 $last_poster = $post['poster']['id'];
 if($last_poster!=0) {
 // Get The Avatar the easy Way
 loadMemberData($last_poster);
 loadMemberContext($last_poster);
 
 $ava = !empty($memberContext[$last_poster]['avatar']['image']) ? $memberContext[$last_poster]['avatar']['href'] : $settings['theme_url'].'/images/default_avatar.png';
 } else {
 $ava = $settings['theme_url'].'/images/default_avatar.png';
 }
 echo'
 <div class="col-xl-3 col-md-6 col-12">
 <div class="info-box">
 <div class="blog-meta">
 <span class="day">',timeformat($post['timestamp'], '%d'), '</span>
 <span class="month">',timeformat($post['timestamp'], '%b'), '</span>
     </div>
 <div class="title">
 <header class="entry-header">
   <h6 class="inverse-font">', $post['link'], '</h6>
 <div class="entry-meta">
 <span class="jp-views"><img class="avatar" src="', $ava, '" />&nbsp;-&nbsp;By&nbsp;', $post['poster']['link'], '</span>
 </div>
 </header>
 </div>
 <div class="content-post">
   <p>', $post['board']['link'], '</p>
 </div>
 </div>
 </div>';
 }
 echo'
 </div><!-- #recent_posts_content -->';


Option fixed 4 on the home page do not want to limit

NOD : I want to do this from the code.

see picture e : http://demo.replikacepsatis.com/index.php

see the following picture

[attach name=sshot-1.png type=image/png]403[/attach]

Chen Zhen

Keep a running count & use a modulus operator.
When your operator does not equal zero have the parent div as block else make it inline.


replikacep


Chen Zhen


Do you want 4 per row or just 4 in total?

replikacep


Chen Zhen

$x = 0;
foreach ($context['latest_posts'] as $post){
$x++;
if ($x > 4)
{break;}

replikacep

Quote from: Chen Zhen on January 24, 2019, 10:56:55 AM$x = 0;
foreach ($context['latest_posts'] as $post){
$x++;
if ($x > 4)
{break;}

was Thank you

bigguy

You should be able to set it to what you want by changing the number.