How to building function for codeigniter such as Wordpress -


i fetch data views, $article['article_title'] article title

<?php foreach ($articles $article) { ?>     <a href="#"><?php echo $article['article_title']; ?></a>     <!-- code here --> <? } ?> 

how create helper using the_title() (same wordpress function) replace $article['article_title'];

<?php foreach ($articles $article) { ?>     <a href="#"><?php echo the_title(); ?></a>     <!-- code here --> <? } ?> 

i created function working id (segment), homepage don't working because not segment.

it's question.

you can way:

create helper e.g.:

function the_title()  {     $ci =& get_instance();      // if url looks http://localhost/this-is-my-page-name     $slug = $ci->uri->segment(1);       if($slug) {         $query = $ci->db->where('slug', $slug)->get('pages')->row();         $result = $query->title;     }     return $result; } 

and can use in article like:

<?php echo the_title(); ?> 

btw. example 1 result, if want list of aricles via foreach loop need modify th code.


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -