Showing posts with label WordPress. Show all posts
Showing posts with label WordPress. Show all posts

Custom Post Types in Wordpress

By // No comments:
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(); ?>

Register Jquery Javascript files

By // No comments:
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

By // No comments:
<?php include(TEMPLATEPATH.'/mygallery/header-include.php'); ?>

HEADER-INCLUDE.PHP
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/mygallery/lightbox.css">

WordPress Theme code

By // No comments:
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();
?>