Saturday 11 January 2014

Add thumbnail in pages - PyroCMS



For adding thumbnail in Pyrocms page....

Simple add a img tag in every page content page body

ex:

<img src="URL OF YOUR IMAGE" id="headerimg" style="display:none;" class="" alt="" title=""/>



Now add this javascript in your default.html under addons > themes > layout.

<script>
(function(){
   
var headerimage = document.getElementById("headerimg").src;
window.onload = function() {
       //when the document is finished loading, replace everything
       //between the <a ...> </a> tags with the value of splitText
   document.getElementById("myLink").src=headerimage;
}

})();

</script>



And finally add an image tag where you want to display your banner image.i used it in main.html under addons > themes > partials.

like this :
<img id="myLink" src="">

For demo

Thanks






How to add active class in Navigation-pyrocms


=== Goodafternoon friends ===

 

For adding active class in navigation for pyrocms,

<div class="content">
<div class="menu-block-2 menu-name-primary-links parent-mlid-0 menu-level-2">
<ul class="menu">
{{ pages:children id="11" limit="12" }}
<li {{ if {url:segments segment="2"} ==  slug  }} class="active" {{ endif }}>
<a href="{{ url }}">{{ title }}</a>
</li>
{{ /pages:children }}
</ul>
</div>
</div>

For working example,click here

I hope this helps.Thanks

Friday 10 January 2014

How to Upload images in codeignitor and save file path in database ?



Here i am using twitter bootstrap theme  

Controller to open form name dashboard.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Dashboard extends CI_Controller {

public function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->model('newcategory');
}
public function category()
{
$data['category'] = $this->newcategory->showcategorydetails();
$this->load->view('template/header',$data);
$this->load->view('template/sidebar');
$this->load->view('category', array('error' => ' ' ));
$this->load->view('template/footer');
}
}

?>




In view- file name category.php

<div id="content">

<div class="outer">

<div class="inner">
<div class="row">
  <div class="col-lg-12">
    <div class="box">
      <header>
        <div class="icons"> <i class="fa fa-table"></i> </div>
        <h5>Dynamic Table</h5>
      </header>
      <div id="collapse4" class="body">
        <table id="dataTable" class="table table-bordered table-condensed table-hover table-striped">
          <thead>
            <tr>
              <th>Image</th>
              <th>Name</th>
              <th>Description</th>
              <th>Slug</th>
              <th>Posts</th>
              <th>Parent</th>
              <th>Status</th>
              <th>Action</th>
            </tr>
          </thead>
          <tbody>
          <?php foreach ($category as $cat) { ?>
            <tr>
              <td><img src="<?php echo base_url(); ?>uploads/<?php echo $cat['img_name']; ?>" class="category-image" alt="category-image"></td>
              <td><?php echo $cat['name']; ?></td>
              <td><?php echo $cat['description']; ?></td>
              <td><?php echo $cat['slug']; ?></td>
              <td>Empty</td>
              <td>
 <?php if($cat['parent']=='0')
 {
echo '-N/A-';
 } else {
 
 $query=$this->db->query("select parent_cat_name from app_category_parent where id=".$cat['parent']);
 $cat_name = $query->result_array();
 foreach ($cat_name as $category) {
 echo $category['parent_cat_name'];
 }}
 ?></td>
              <td><?php if($cat['status']=='1'){ echo 'Active';} else { echo 'Inactive'; } ?></td>
              <td>            
              <a href="<?php echo base_url(); ?>index.php/newentry/deactivate_Category/<?php echo $cat['id']; ?>" class="customClick btn btn-warning btn-xs btn-line" data-str="0">De-activate</a>
              <a href="<?php echo base_url(); ?>index.php/newentry/delete_Category/<?php echo $cat['id']; ?>" class="deleteClick btn btn-danger btn-xs btn-line" data-str="0">Delete</a>
              </td>
            </tr>
          <?php } ?>
          </tbody>
        </table>      
      </div>
    </div>
  </div>
</div>
<div class="row">
  <div class="col-lg-6">
    <div class="box dark">
      <header>
        <div class="icons">
          <h5>Add New Category</h5>
          <div class="toolbar">
            <ul class="nav">
              <li> <a class="minimize-box" href="#div-1" data-toggle="collapse"> <i class="fa fa-chevron-up"></i> </a> </li>
            </ul>
          </div>
        </div>
      </header>
      <div id="div-1" class="accordion-body collapse in body">
        <?php echo form_open_multipart('newentry/newcategory') ?>

// for saving data from this form into database-newentry is my controller and newcategory is the function.


          <div class="form-group">
            <label class="control-label col-lg-4" for="text1">Name</label>
            <div class="col-lg-8">
              <input id="cat_title" class="form-control" name="cat_title" type="text" required="required" onblur="getslug();">
              <p>The name is how it appears on your site.</p>
            </div>
          </div>
          <div class="form-group">
            <label class="control-label col-lg-4" for="text1">Slug</label>
            <div class="col-lg-8">
              <input id="cat_slug" class="form-control" name="cat_slug" type="text" required="required">
              <p>The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.</p>
            </div>
          </div>
          <div class="form-group">
            <label class="control-label col-lg-4">Parent</label>
            <div class="col-lg-8">
              <select name="cat_parent" onchange="selected();" id="cat_parent" data-placeholder="Choose a Country..." class="form-control chzn-select" tabindex="2">
              <option value="">None</option>
              <?
 $query=$this->db->query("select app_category.*,app_category_detail.* FROM app_category LEFT JOIN app_category_detail ON app_category.cat_id=app_category_detail.cat_id where status=1");
 $cat_name = $query->result_array();
 foreach ($cat_name as $category) { ?>
           
 <option value="<?php echo $category['cat_id'];?>"><?php echo $category['name'];?></option>
           
 <? } ?>            
              </select>            
              <input type="hidden" id="cat_parent_id" name="cat_parent_id" />
              <p>Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.</p>
            </div>
          </div>
          <div class="form-group">
            <label class="control-label col-lg-4" for="autosize">Description</label>
            <div class="col-lg-8">
              <textarea id="autosize" name="cat_description" class="form-control" style="overflow: hidden; word-wrap: break-word; resize: horizontal; height: 134px;"></textarea>
              <p>The description is not prominent by default; however, some themes may show it.</p>
            </div>
          </div>  
       
 <div class="form-group">
                        <label class="control-label col-lg-4">Category Image</label>
                        <div class="col-lg-8">
                          <div class="fileinput fileinput-new" data-provides="fileinput">
                            <div class="fileinput-new thumbnail" style="width: 200px; height: 150px;">
                              <img data-src="holder.js/100%x100%" alt="...">
                            </div>
                            <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"></div>
                            <div>
                              <span class="btn btn-default btn-file"><span class="fileinput-new">Select image</span><span class="fileinput-exists">Change</span>
                              <input type="file" name="userfile" size="20" />
                              </span>
                              <a href="#" class="btn btn-default fileinput-exists" data-dismiss="fileinput">Remove</a>
                            </div>
                          </div>
                        </div>
                      </div>
           
 
          <p class="submit">
            <input id="submit" class="btn btn-primary" type="submit" value="Add New Category" name="submit">
          </p>
        </form>
     
      </div>
    </div>
  </div>
</div>
</div>
</div>
</div>
<script>
function getslug() {
var str = document.getElementById('cat_title').value;
var res = str.replace(/\s+/g, '-').toLowerCase(); document.getElementById('cat_slug').value = res; }
</script>
<script>
function selected()
{
var id = document.getElementById('cat_parent').value; document.getElementById('cat_parent_id').value=id;
}
</script>






In My controller - name - newentry.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Newentry extends CI_Controller {


public function __construct()

{

parent::__construct();

$this->load->helper('url');

$this->load->model('newcategory');

}

public function newcategory()

{

$this->newcategory->newcategory_partone();

$id = $this->db->insert_id();

$this->newcategory->newcategory_parttwo($id);

$cid=$this->input->post('cat_parent_id');

if ($cid !='') {

$this->newcategory->newcategory_partthree();

}

redirect('dashboard/category', 'refresh');

}

public function deactivate_Category(){

$id=$this->uri->segment(3);

$this->newcategory->deactivate_category($id);

redirect('dashboard/category', 'refresh');

}

public function delete_Category(){

$id=$this->uri->segment(3);

$this->newcategory->delete_category($id);

redirect('dashboard/category', 'refresh');

}

}






And in my model - name- newcategory.php



<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Newcategory extends CI_Controller {

public function __construct()
{
parent::__construct();
}
public function lastregistration_id()
{
return $this->db->insert_id();
public function newcategory_partone()
{
$this->load->helper('url');
$this->load->helper('form');
$this->load->helper('date');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width']  = '1024';
$config['max_height']  = '768';

$this->load->library('upload', $config);

if ( ! $this->upload->do_upload())
{
redirect('dashboard/category', 'refresh');
}
else
{
$data = array('upload_data' => $this->upload->data());
            foreach ($data as $item){
$img_path= $item['full_path']; 
$img_name= $item['file_name']; 
}
$cat = array(
'name' => $this->input->post('cat_title'),
'slug'=>$this->input->post('cat_slug'),
'date_created' => date('Y-m-d H:i:s'),
'system_ip'=> $_SERVER['REMOTE_ADDR'],
'img_name' =>$img_name,
'img_path'=>$img_path,
);
return $this->db->insert('app_category', $cat);
}
}
public function newcategory_parttwo($cat_id)
{
$this->load->helper('url');
$this->load->helper('date');
$cat_second = array(
    'cat_id' =>$cat_id,
'name'=>$this->input->post('cat_title'),
'description'=>$this->input->post('cat_description'),
'parent'=>$this->input->post('cat_parent'),
);
return $this->db->insert('app_category_detail', $cat_second);
}
public function newcategory_partthree()
{
$this->load->helper('url');
$this->load->helper('date');
$id=$this->input->post('cat_parent_id');
$query=$this->db->query("select * from app_category where cat_id=$id");
$cat_name = $query->result_array();
foreach ($cat_name as $category) { 
        $name=$category['name'];
        }
$cat_third = array(
   
'parent_cat_name'=>$name,
'status' =>1,
);
return $this->db->insert('app_category_parent', $cat_third);
}
public function showcategorydetails()
{
$query=$this->db->query("select app_category.*,app_category_detail.* FROM app_category LEFT JOIN app_category_detail ON app_category.cat_id=app_category_detail.cat_id where status=1");  
    return $query->result_array();
}
public function deactivate_category() {
$id=$this->uri->segment(3);
$data = array(
              'status '=>0
            );

$this->db->where('id', $id);
$this->db->update('app_category_detail', $data); 
}
public function delete_category() {
$id=$this->uri->segment(3);
$data = array(
             'status '=>2 
            );

$this->db->where('id', $id);
$this->db->update('app_category_detail', $data); 
}
}


That's it.Enjoy.


Sunday 5 January 2014

Style last post in loop differently?



How to add different class in last child of loop in wordpress.



<ul class="categories_list cat_main">
<?php  
$args=array('posts_per_page' => 6,'post_type' => 'post','orderby' => 'meta_value', 'meta_key' => 'views','order'=> 'DESC', 'post_status' => 'publish');
$the_query = new WP_Query($args);
$counter=1;
while ($the_query->have_posts()) : $the_query->the_post();?>  
      <li <?php if($counter==6){echo "class='last'";}?>>
      <div id="normal">
      <a href="<?php the_permalink(); ?>">
      <?php $values = get_post_custom_values("Featured Image");  ?>
      <img src="<?php echo $values[0];?>" /></a>
      </div>
      <?php /*?><div id="mob">
      <?php $values_m = get_post_custom_values("mobile Link");  ?><a href="<?php echo $values_m[0];?>">
      <?php $values = get_post_custom_values("Featured Image");  ?>
      <img src="<?php echo $values[0];?>" /></a>
      </div><?php */?>
      <p class="title"><a href="<?php the_permalink(); ?>">
        <?php the_title(); ?>
        </a></p>
      <?php /*?><p class="mob_title"><?php $values_m = get_post_custom_values("mobile Link");  ?><a href="<?php echo $values_m[0];?>">
        <?php the_title(); ?>
        </a></p><?php */?>
      <p>
        <?php $values1 = get_post_custom_values("views");?>
        <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?>
        |
        <?php if(function_exists('the_views')) { the_views(); } ?>
      </p>
    </li>
    <?php $counter++; ?>
     <?php endwhile; ?>
    <?php wp_reset_query(); ?>
  </ul>



Thanks.