Friday, 31 May 2013

dispaly images custom plugin

<!--<style type="text/css">
#event-icon{ background:url("../images/events-screen-icon.png");}
</style>-->
<script type="text/javascript">
function validate()
{
var delete_data=confirm("Do you really want to delete this row?");
if(delete_data==false)
{
return false;
}
else
{
return true;
}
}

</script>

</head>

<body>
<div class="wrap">
<div id="event-icon"></div>
<h2><?php echo '<img src="' . plugins_url( 'images/event1.png' , __FILE__ ) . '" > ';?>
CAST AND CREW DETAILS</h2>
<form name="form1"  id="form1" method="post" action="" enctype="multipart/form-data">
 
<?php
global $wpdb;
$url = admin_url( 'admin.php?page=add-image', '' );
$url2 = admin_url('admin.php?page=cast_crew/cast_crew_table.php', '');

$table_name = $wpdb->prefix . "tblcast_crew";

//Pagination

$rowsPerPage = 2;  //number of rows per page

$currentPage = ((isset($_GET['page_new']) && $_GET['page_new'] > 0) ? (int)$_GET['page_new'] : 1);

//limit=rowsperpage  start=offset

$offset = ($currentPage-1)*$rowsPerPage;

$query="SELECT * FROM $table_name LIMIT ".$offset.",".$rowsPerPage;
$row=$wpdb->get_results($query);

//Get Admin Page parent

//$a=get_admin_page_parent();
//echo "<br/>"."Admin Page parent is :".$a."<br/>";

//Get Plugin URL

//$plugins_url = plugins_url();
//echo "<br/>"."Plugin URL : ".$plugins_url."<br/>";

//Get Admin URL

//$adminurl=get_admin_url();
//echo "<br/>"."Admin URL : ".$adminurl;

?>

<table width='600' border='1' class='widefat'>
<thead>
          <tr>
             <th>Id</th>
             <th>Title</th>
             <th>Photo</th>
             <th>Description</th>
             <th>Designation</th>
             <th>Photo By</th>
             <th>Delete</th>
             <th>Update</th>
        </tr>
     </thead>
   
<tr>
     <?php

foreach ( $row as $row1 )
{
// $upload_dir=wp_upload_dir();
$TARGET_PATH="/wp-content/uploads/mydir/";
//echo $TARGET_PATH.$row1->image;
$path=get_site_url().$TARGET_PATH;
//echo plugins_url('cast_crew/upload/');

$id=$row1->id;
?>
<td><?php echo $row1->id; ?></td>
        <td><?php echo $row1->image_title; ?></td>
        <td><img src="<?php echo $path.$row1->image; ?>" width="40" height="40"/></td>
<td><?php echo $row1->image_desc; ?></td>
        <td><?php echo $row1->image_desig; ?></td>
         <td><?php echo $row1->image_by; ?></td>

     
       <td><a href="<?php echo $url2;?>&id=<?php echo $id; ?>" onClick="return validate();"><img src="<?php echo plugins_url('cast_crew/images/delete.jpeg') ?>"  width="15" height="15"></a></td>
<!-- <td><a  href="<?php echo $url2;?>&id=<?php echo $id; ?>" onClick="return validate();">Delete</a></td>
-->
<!-- <td><a href="<?php echo $url;?>&id=<?php echo $id;?>">Update</a></td>
-->
<td><a href="<?php echo $url;?>&id=<?php echo $id;?>"><img src="<?php echo plugins_url('cast_crew/images/edit.jpeg') ?>" width="25" height="25"></a></td>
    </tr>
<input name='id' type='hidden' value='$id'/>
<?php
}
?>
</table>

<?php
//retrieve number of entries in a table

$results = $wpdb->get_results("SELECT id FROM $table_name");
$c=1;
$total= count($results);
//echo "Total rows".$total;
//echo "<br/>"."Rows per page".$rowsPerPage;
$total_pages = $total;
$totalPages = ceil($total_pages / $rowsPerPage);
?>
                <br/><br/>
<!--echo "pages".$totalPages;-->
                &nbsp;&nbsp;

<?php

// page

//echo "Page no. ".$currentPage;
echo "&nbsp;"."&nbsp;";

if($currentPage > 1) {

echo "<a href='$url2&page_new=" . ($currentPage - 1) . "'>Previous Page</a>";

}
echo "&nbsp;"."&nbsp;";

echo $currentPage;

echo "&nbsp;"."&nbsp;";
if($currentPage < $totalPages) {
echo "<a href='$url2&page_new=" . ($currentPage + 1) . "'>Next Page</a>";

}

   if(isset($_GET['id']))
  {
$id = $_GET["id"];
$table_name = $wpdb->prefix . "tblcast_crew";
$del_row=$wpdb->get_row("SELECT image FROM $table_name WHERE id = " . $id);
$image_name=$del_row->image;

    $upload_dir = wp_upload_dir();
$TARGET_PATH=$upload_dir['basedir']."/"."mydir";


if($TARGET_PATH."/".$image_name)
{
  $sql = "DELETE FROM " . $table_name . " WHERE id = " . $id;
  $result = $wpdb->query($sql);
  unlink($TARGET_PATH."/".$image_name);
}
else
{
  echo "Image Not Found...!";
}

}
?>
</form>
    </div>
</body>
</html>



Custom Pluign Cast and crew

<?php
/* Events plugin

Plugin name: My Cast And Crew page plugin.
Description: This is a plugin Cast And Crew page for image Uploader.
*/

register_activation_hook(__FILE__,'castcrewplugin_install');  
register_deactivation_hook(__FILE__ , 'castcrewplugin_uninstall' );

function castcrewplugin_install()
{
global $wpdb;
$table_name = $wpdb->prefix . "tblcast_crew";    //tablename
   
$sql = "CREATE TABLE $table_name (
  id mediumint(9) NOT NULL AUTO_INCREMENT,
image_title VARCHAR(50) DEFAULT '' NOT NULL,
image VARCHAR(200) DEFAULT '' NOT NULL,
image_desc VARCHAR(200) DEFAULT '' NOT NULL,
image_desig VARCHAR(200) DEFAULT '' NOT NULL,
image_by VARCHAR(200) DEFAULT '' NOT NULL,
PRIMARY KEY id (id),UNIQUE KEY image_title (image_title)
    );";

   require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );  //dbDelta function in upgrade.php
   dbDelta( $sql );

}
       
function castcrewplugin_uninstall()
{
global $wpdb;
$table_name=$wpdb->prefix . "tblcast_crew";
$sql="DROP TABLE if exists $table_name ";
$wpdb->query($sql);    
}

add_action('admin_menu','castcrew_admin_menu');

function castcrew_admin_menu() {

//Syntax:
//add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url,     $position );

 add_menu_page(
"Cast_and_Crew",
"CAST AND CREW",
'1',
__FILE__,
"display_images",plugins_url( 'cast_crew/images/icon.png' ),8
);

//Syntax :

//add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );

add_submenu_page(__FILE__ , 'add', 'ADD', '8','add-image',
'addimages');  //add-user add-event

}

function display_images()
{
include "display_images.php";
}

function addimages()
{  
include "addimages.php";
}

?>

Insert featured image in div style background

<?php
if ( has_post_thumbnail()) {
   $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large');
   echo '<div style="background:url(' . $large_image_url[0] . ') no-repeat;"></div>';
}
?>
 
 this returns a <img scr source when opening in chrome, how go i get 
the the_post_thumbnail to just give me the source of the file without 
<img scr?
 
 
<div id="container">
  <div id="gigpres"> 

<div style="background: url(<img width="150" height="150" src="http://xxxx/the-2-live-crew-150x150.jpg" class="attachment-thumbnail wp-post-image" alt="the-2-live-crew" title="the-2-live-crew" />) !important;">adasdasdasd </div>
  </div>
  </div> 

Friday, 24 May 2013

Google Like Suggetion box


Need some quick help. Please see my code below. When I start typing in the search box the Suggestions are shown below as a table but i need them like Google suggest(live search).

Please help me on this.
Code (text):

HTML FILE

<html>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form>
<input type="text" id="txt1" size="30" onkeyup="showUser(this.value)" autocomplete="off" />
<div id="livesearch"></div>
</form>
<br />
<div id="txtHint"><b>Your group will be listed here</b></div>

</body>
</html>


<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', 'root', '');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("needsesearch", $con);

$sql="SELECT title FROM `jos_sections` WHERE title like  '%".$q."%' ";

$result = mysql_query($sql);

echo "<table border='1'>
<tr>




</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";

  echo "<td>" . $row['title'] . "</td>";


  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

Wednesday, 22 May 2013


How to Create a Separate Page for Blog Posts in WordPress

 

By default WordPress display your content in a blog format on the homepage. Users often modify for their needs by creating a custom home page in WordPress. What if you want to use WordPress to run your entire static site, and also use it as a blog? Well in this article, we will show you how to create a separate page for blog posts in WordPress.
There are few different methods you can use to create a separate page for blog posts. It all depends on which method you used to create the custom home page. If you created the homepage by creating a file called home.php, then you want to follow the method below:
1. First copy your index.php file and save it as blog.php.
2. Make it a Custom WordPress Page Template.
3. Create a new WordPress page in your WP-Admin panel. Title the page Blog, and before you hit publish, make sure you select the custom page template as shown in Step 2.
4. Publish the Page.
Next you need to edit blog.php file. Find the Loop, which should look something like this:
1<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
Replace this top part with the code below:
1<?php
2$temp = $wp_query;
3$wp_query= null;
4$wp_query = new WP_Query();
5$wp_query->query('posts_per_page=5'.'&paged='.$paged);
6while ($wp_query->have_posts()) : $wp_query->the_post();
7?>
The posts_per_page variable does exactly what it sounds like. It tells WordPress to display X amount of posts on each page. You may change the number from 5 to whatever you like.
Find a line that looks like this:
1<?php else : ?>
Remove this code and any else code such as the 404 content etc. You should already have a 404.php file in place for that.
Next you need to find this code:
1<?php endif; ?>
Replace it with:
1<?php $wp_query = null; $wp_query = $temp;?>
Ladies and gentleman, you now have a separate page for blog posts. Depending on your permalink structure, you can link it in other sites such as twitter, facebook etc. You can also list it in your navigation bar with the WordPress 3.0 Custom Menus.

Method 2

If you want to use the built-in Static / Blog page method, then you can do so as well. This method is less code intensive, but it does not allow for customizations that some developers might want.
Create two new pages, one can be called “Welcome” or whatever you want to call your homepage. The next should be called “Blog” or whatever you want to call your blog page.
If you already have a file called home.php in your theme, then you will need to rename it to welcome.php and make it a Custom WordPress Page Template by adding the codes at the top. Then in your Welcome page, select the Welcome Template.
Go to Settings » Reading: