CUSTOM POST TYPES
<?php
register_post_type('snippet',array(
'public' => true,
'label' => 'Snippet',
'labels' => array(
'add_new_item' => 'Add New Snippet'
),
'supports' => array('title','editor','comments','thumbnail','excerpt')
));
?>
TO CREATE CATEGORIES & TAGS
<?php
'taxonomies' => array('category','post_tag')
add_action('init','custom_post_type');
?>
NEW TAXONOMY
<?php
add_action('init',function(){
register_taxonomy('language','snippet',array(
'label' => 'Language'
));
});
?>
RESAVE PERMALINKS TO DISPLAY CUSTOM POST TYPES
TO DISPLAY TAXONOMY FOR CUSTOM POST TYPES
<?php
echo get_the_term_list(get_the_id(),'language','',',');
?>
TO DISPLAY TAGS
<?php the_tags(); ?>
Custom Post Types in Wordpress
Register Jquery Javascript files
REGISTER JQUERY JAVASCRIPT FILES
<?php
function load_my_scripts(){
wp_register_script('jquery', get_template_directory_uri().'/jquery.min.js');
wp_register_script('my_lightbox', get_template_directory_uri().'/js/lightbox.js', array('jquery'));
wp_register_script('my_gallery', get_template_directory_uri().'/js/gallery.js', array('jquery'));
wp_enqueue_script('my_lightbox');
wp_enqueue_script('my_custom');
}
add_action('wp_enqueue_scripts','load_my_scripts');
?>
WordPress include
<?php include(TEMPLATEPATH.'/mygallery/header-include.php'); ?> HEADER-INCLUDE.PHP <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/mygallery/lightbox.css">
Responsive codes
RESPONSIVE CODES
<meta name="viewport" content="width=device-width">
@media only screen and (min-width: 1px) and (max-width: 650px){
}
WordPress Theme code
WordPRess theme
<?php bloginfo('template_url' ); ?>/images/logo.jpg
WP MENU
<?php wp_nav_menu(array('theme_location' => 'primary')); ?>
SITE URL
<?php bloginfo('url'); ?>
SHORTCODE
<?php echo do_shortcode('[shortcode]'); ?>
FUNCTIONS.PHP => CTRL+F => SIDEBAR => COPY PASTE WIDGET CODE
name => (change name)
ID => (change ID)
description => (change DESC)
/* <?php dynamic_sidebar('ID'); ?> */
<?php dynamic_sidebar('sidebar-4'); ?>
FUNCTIONS.PHP => FIND => MENU
<? register_nav_menu('footer_menu'__( 'Footer Menu', 'twentytwelve')); ?>
IN FOOTER ADD THIS TO SHOW FOOTER MENU
<?PHP wp_nav_menu(array('theme_location' => 'footer_menu')); ?>
CODE FOR POSTS LOOP
<?php
$posts = new WP_Query(array(
'posts_per_page' => 5, //-1 for unlimited posts
'offset' => 0, //starting posts from zero
'category_name' => 'events', //events is category slug
'post_type' => 'post',
'post_status' => 'publish'
));
if($posts -> have_posts()):
while ($posts -> have_posts()): $posts -> the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<?php the_post_thumbnail(); ?>
<a href="<?php the_permalink(); ?>">Read more</a>
<?php endwhile;
else:
echo "No posts here";
endif;
wp_reset_query();
?>
Next and Previous Buttons
NEXT AND PREVIOUS BUTTONS
<?php
if(isset($_REQUEST['ind']))
$sind = $_REQUEST['ind'];
else
$sind = 0;
$totrec = 5;
mysql_connect("localhost","root","");
mysql_select_db("information_schema");
$data = mysql_query("select * from character_sets limit $sind, $totrec");
while($rec=mysql_fetch_row($data)){
echo "<tr><td>$rec[0]<td>$rec[1]<td>$rec[2]";
}
echo "</table>";
if($sind!=0){
$pind = $sind - $totrec;
echo "<a href='demo.php?ind=$pind'>Previous</a>";
}
$nind = $sind + $totrec;
echo "<a href='demo.php?ind=$nind'>Next</a>";
//to stop display next button on last page
$data1 = mysql_query("select * from character_sets");
$trec = mysql_num_rows($data1);
if($nind < $trec){
echo "next";
}
?>
Upload file to database
UPLOAD FILE TO DATABASE
<form method="post" action="" enctype="multipart/form-data">
Select file: <input type="file" name="f1">
<input type="submit" name="sub" value="UPLOAD">
</form>
<?php
if(is_uploaded_file($_FILES['f1']['tmp_name'])){
mysql_connect("localhost","root","");
mysql_select_db("test");
$cont = file_get_contents($_FILES['f1']['tmp_name']);
$cont = addslashes($cont);
if(mysql_query("insert tbl_images values ('','$cont')"))
echo "Image added";
else
echo "not";
}
?>
Store images in database
HOW TO STORE IMAGES IN DATABASES
<?php
mysql_connect("localhost","root","");
mysql_select_db("test");
$cont = file_get_contents("winter.jpg");
$cont = addslashes($cont);
if(mysql_query("insert into tbl_images values('','$cont')"))
echo "IMage is added";
else
echo "not";
?>
TABLE
sno int auto_increment primary key, image BLOB or LONG BLOB
RETRIEVE IMAGES FROM DATABASE
<?php
header("Content-type:image/jpeg");
mysql_connect("localhost","root","");
mysql_select_db("test");
$data = mysql_query("select * from tbl_images where imgid=3");
$rec = mysql_fetch_row($data);
echo $rec[1];
?>
INSERT statement SQL
insert into tbl_user (uname) values ('John');
insert into tbl_user values ('alex','alex123'),('rajesh','rajesh123');
Sessions Login Logout
<?php
if(isset($_POST['sub'])){
$uname = $_POST['txtuname'];
$pwd = $_POST['txtpwd'];
if($uname=="scott" and $pwd=="scott123"){
session_start();
$_SESSION['aut'] = true;
echo "<script>location='welcome.php';</script>";
}
else{
echo "invalid";
}
}
?>
<form method="post" action="">
Username:<input type="text" name="txtuname">
Password:<input type="password" name="txtpwd">
<input type="submit" name="sub" value="login">
</form>
WELCOME.PHP
<?php
session_start();
if(isset($_SESSION['aut'])){
echo "Welcome to user";
}
else{
echo "<script>location='login.php';</script>";
}
?>
<a href="logout.php">Logout</a><link rel="canonical" href="">
LOGOUT.PHP
<?php
session_start();
session_destroy();
echo "Logout successful";
?>
File Upload in php
<form method="post" action="" enctype="multipart/form-data">
Select File: <input type="file" name="f1">
<input type="submit" name="sub" value="Upload">
</form>
<?php
if(is_uploaded_file($_FILES['f1']['tmp_name'])){
$fname = $_FILES['f1']['name'];
if(move_uploaded_file($_FILES['f1']['tmp_name'], "../testing/$fname"))
echo "File moved";
else
echo "File not moved";
}
else
echo "File not uploaded";
?>