Vote count:
0
I display boxes with news. Every box is from a different category.
Here is the screenshot of what I try to accomplish:
Display boxes with news from every category
But check only the design, leave the PHP code. It is outdated question. (Sorry for putting this link, but I cannot attach images. Low scores)
After the main post I try to show the rest of the news, but i can only display the main post and after that the list with posts in which the first post is duplicated.
Here is my code:
public function category_box($category_id, $category_name) {
$this->_db->query("SELECT * from posts WHERE category_id = '$category_id'");
$this->current_category_posts = $this->_db->resultset();
$posts = array();
foreach ($this->current_category_posts as $post) {
if ($post['category_id'] === $category_id) {
$posts[] = $post;
}
}
include VIEWS_PATH . 'homepage/category_box.php';
}
And this is one view file for the category box:
<div class="category-box">
<div class="category-name">
<?php print $category_name ?>
</div><!-- end div.category-name -->
<div class="category-box-content">
<h2><a href="#"><?php print $post['post_title']; ?></a></h2>
<div class="published-date">
<?php print $post['post_published_date']; ?>
</div><!-- end div.published-date -->
<div class="main-photo">
<a href="#"><img src="<?php print BASE_URL . 'public/uploads/images/' . $post['post_photo']; ?>" alt=""></a>
<span class="photo-caption">
<?php print $post['post_photo_caption']; ?>
</span><!-- end div.photo-caption -->
</div><!-- end div.main-photo -->
<div class="excerpt">
<a href="#"
title="<?php print $post['post_content']; ?>"><?php print $post['post_content']; ?></a>
</div><!-- end div.excerpt -->
<div class="latest-posts">
<div class="more-publications">
More publications in <?php print $category_name ?>
</div>
<ul>
<?php
foreach ($this->current_category_posts as $post_in_list) {
if ($post_in_list['category_id'] === $category_id) {
print '<li><a href="#" title="' . $post_in_list['post_title'] . '" >' .
$post_in_list['post_title'];
'</a></li>';
}
}
?>
</ul>
<a href="#" class="all-publications">All publications »</a>
<div class="clearfix"></div>
</div><!-- end div.latest-posts -->
</div><!-- end div.category-box-content -->
</div><!-- end div.category-box -->
This is how I display each box (maybe not important for the question):
$post->category_box("1", "World");
$post->category_box("2", "Politics");
$post->category_box("3", "Culture");
$post->category_box("4", "Technologies");
$post->category_box("5", "Sports");
$post->category_box("6", "Art");
How can I accomplish this?
Thank you very much!
asked 3 mins ago
Aucun commentaire:
Enregistrer un commentaire