buster808 Posted April 18, 2019 Share Posted April 18, 2019 Hi, I have the PHP code below which creates my blog list into rows. How can I use UiKit to create the content output into say 3 colums or 4? A point in the right directions would be helpful thanks. <?php $entries = $pages->find('template=blog-entry')->sort('-created'); $publish_date = date('Y-m-d', $page->created); foreach($entries as $entry) { $content .= "<a href='{$entry->url}'> <h2>{$entry->title}</h2><h4>{$publish_date}</h4></a>"; $content .= shortText($entry->body,100); $content .= "<br><a href='{$entry->url}'> Read More </a>"; } function shortText($text, $maxlength = 100) { // truncate/shorten to max length $text = substr(strip_tags($text), 0, $maxlength); // check if we've truncated to a spot that needs further truncation if(strlen(rtrim($text, ' .!?,;')) == $maxlength) { // truncate to last word $text = substr($text, 0, strrpos($text, ' ')); } return trim($text); } Link to comment Share on other sites More sharing options...
ukyo Posted April 18, 2019 Share Posted April 18, 2019 You can surround your list with grid component. <!-- 3 columns, for 4 columns, uk-child-child-width-1-4@m --> <div class="uk-child-width-1-1 uk-child-width-1-3@m" uk-grid> <div> Blog Title 1 </div> <div> Blog Title 2 </div> <div> Blog Title 3 </div> <div> Blog Title 4 </div> <div> Blog Title 5 </div> </div> Link to comment Share on other sites More sharing options...
buster808 Posted April 18, 2019 Author Share Posted April 18, 2019 Thanks for the reply ukyo Do you mean like this? sorry if Im being silly here. <div class="uk-child-width-1-1 uk-child-width-1-3@m" uk-grid> <?php foreach ($entries as $entry) { $content .= "<a href='{$entry->url}'> <h2>{$entry->title}</h2><h4>{$publish_date}</h4></a>"; $content .= shortText($entry->body, 100); $content .= "<br><a href='{$entry->url}'> Read More </a>"; } ?> </div> Link to comment Share on other sites More sharing options...
dragan Posted April 18, 2019 Share Posted April 18, 2019 8 minutes ago, buster808 said: Thanks for the reply ukyo Do you mean like this? sorry if Im being silly here. <div class="uk-child-width-1-1 uk-child-width-1-3@m" uk-grid> <?php foreach ($entries as $entry) { $content .= "<div><a href='{$entry->url}'> <h2>{$entry->title}</h2><h4>{$publish_date}</h4></a>"; $content .= shortText($entry->body, 100); $content .= "<br><a href='{$entry->url}'> Read More </a></div>"; } ?> </div> I think rather like this ? (inner divs) Link to comment Share on other sites More sharing options...
dragan Posted April 18, 2019 Share Posted April 18, 2019 oh, and for accessibility's sake, don't jump over heading hierarchies, i.e. don't use an h4 right after an h2. Use h3 instead. https://www.w3.org/WAI/tutorials/page-structure/headings/ Plus, I'd suggest to place your anchors inside h2, not outside. Link to comment Share on other sites More sharing options...
buster808 Posted April 18, 2019 Author Share Posted April 18, 2019 Hi Dragan thanks for your help. <div class="uk-child-width-1-1 uk-child-width-1-3@m" uk-grid> wont output above the php tag. but adding the inline div was helpful just need to get the tag above to work. Pulling my last hair out ha Link to comment Share on other sites More sharing options...
buster808 Posted April 18, 2019 Author Share Posted April 18, 2019 got it working now by doing this - really need to learn php basics <?php $content .= "<div class='uk-child-width-1-1 uk-child-width-1-3@m' uk-grid>"; ?> <?php foreach ($entries as $entry) { $content .= "<div> <a href='{$entry->url}'> <h2>{$entry->title}</h2><h4>{$publish_date}</h4></a>"; $content .= shortText($entry->body, 100); $content .= "<br><a href='{$entry->url}'> Read More </a></div>"; } ?> <?php $content .= "</div>"; ?> Link to comment Share on other sites More sharing options...
ukyo Posted April 18, 2019 Share Posted April 18, 2019 42 minutes ago, buster808 said: got it working now by doing this - really need to learn php basics <?php $content .= "<div class='uk-child-width-1-1 uk-child-width-1-3@m' uk-grid>"; ?> <?php foreach ($entries as $entry) { $content .= "<div> <a href='{$entry->url}'> <h2>{$entry->title}</h2><h4>{$publish_date}</h4></a>"; $content .= shortText($entry->body, 100); $content .= "<br><a href='{$entry->url}'> Read More </a></div>"; } ?> <?php $content .= "</div>"; ?> A tip, if your all code php in your template, you don't need to clode php tag. And no need to close and open tag again again <?php $content .= "<div class='uk-child-width-1-1 uk-child-width-1-3@m' uk-grid>"; foreach ($entries as $entry) { $content .= "<div> <a href='{$entry->url}'> <h2>{$entry->title}</h2><h4>{$publish_date}</h4></a>"; $content .= shortText($entry->body, 100); $content .= "<br><a href='{$entry->url}'> Read More </a></div>"; } $content .= "</div>"; Link to comment Share on other sites More sharing options...
buster808 Posted April 18, 2019 Author Share Posted April 18, 2019 Thanks ukyo Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now