Create News archives |
[eluser]Lykos22[/eluser]
I'd like some help please. I'd like to create a news archive in order to display it on the sidebar. This is what I 'm trying to achieve: Code: 2014 These are the model functions: Code: // function get() is in MY_Model.php and this is my view: Code: <ul class="nav nav-sidebar"> The problem is I get the data like this: Code: Array
[eluser]Tim Brownlaw[/eluser]
Hi, In your Model You can change this... return $this->db->get($this->_table_name)->$method(); to $query = $this->db->get($this->_table_name)->$method(); return $query->result(); Cheers
[eluser]Lykos22[/eluser]
[quote author="Tim Brownlaw" date="1397594078"]Hi, $query = $this->db->get($this->_table_name)->$method(); return $query->result(); Cheers[/quote] The method ($method) is set as the result() already, that's why I'm getting all records.
[eluser]Lykos22[/eluser]
The result should return like this: Code: Array
[eluser]InsiteFX[/eluser]
Try this. Code: public function get_archives(){ NOTE: Not tested!
[eluser]CroNiX[/eluser]
[quote author="Lykos22" date="1401371744"]The result should return like this: Code: Array There is nothing in native CI that will return a result set like that. You'd have to do that in your view while in your loop. Just create a variable to store the $current_year before the loop, and in the loop do a compare to see if ($archive->year == $current_year), if not you've hit a new year and set $current_year = $archive->year and then output the year in a new <li>. It's a bit more complex than that but hopefully that will get you started.
[eluser]Lykos22[/eluser]
@InsiteFX: Thanks! I did some small changes though Code: public function get_archives($limit_to_months = 12) { Code: Array and this is how I display them on my vew Code: <ul>
[eluser]Lykos22[/eluser]
I have one more question, if possible. How can I display the data in two collumns? So that It will look like this Code: <ul>
[eluser]Tpojka[/eluser]
If want to use tw bootstrap >3.0, there is type in code. Should be Code: <div class="col-md-6"> edit: use mod or div functions for opening and closing tags Code: <div class="row"> disclaimer: not tested |
Welcome Guest, Not a member yet? Register Sign In |