Monday, December 22, 2014

Wordpress conditional and custom post registration

Document needs for simple dynamic slider:

All are implement in function.php

slider:

add_action( 'init', 'slider_custom_post' );
function slider_custom_post() {
register_post_type( 'slider-items',
array(
'labels' => array(
'name' => __( 'slider' ),
'singular_name' => __( 'slide' ),
'add_new_item' => __( 'Add New slider' )
),
'public' => true,
'supports' => array('author', 'thumbnail', 'title'),
'has_archive' => true,
'rewrite' => array('slug' => 'slider-item'),
)
);
}

 add image croping in function.php:

add_image_size( 'slider-image', 1900, 654, true );

 add image support:

Add below this code in your  slider.php:

<?php
global $post;
$args = array( 'posts_per_page' => -1, 'post_type'=> 'slider-items');
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>

  <li data-thumb="< ?php echo $slider_image[0]; ?>">
<?php the_post_thumbnail('slider-image'); ?>

<?php endforeach; ?>

page.php script: if you want to dynamic page in your blog or website you copy below this code and paste in your page.php: 

 <?php get_header();?>
<?php if(have_posts()) : ?>< ?php while(have_posts()) : the_post(); ?>

<div class="row">
<div class="col-sm-12">
<?php the_content(); ?>
</div>

</div>
<?php endwhile; ?>

<?php else : ?>
<div class="post">
<h3>< ?php _e('404 Error: Not Found', 'brightpage'); ?>
</div>
<?php endif; ?> 

 Active jquery from Wordpress:

if you want to active wordpress jquery in your website then you copy below this code and paste in function.php

/*for calling jquery*/
function latest_jquery_call() {
wp_enqueue_script('jquery');
}
add_action('init', 'latest_jquery_call');  

Simple Dynamic menu: 

if you want to active dynamic menu in your blog then you type below this code location  this: 

function.php

// This theme uses wp_nav_menu() in one location.

register_nav_menus( array(
'mainmenu' => __( 'Mainmenu Menu'),
) );

 header.php

<? ?php wp_nav_menu( array( 'theme_location' => 'mainmenu', 'menu_class' => 'container' ) ); ?> 

An amazing read more function:

functions.php

function excerpt($num) {$limit = $num+1; $excerpt = explode(' ', get_the_excerpt(), $limit);
array_pop($excerpt);
$excerpt = implode(" ",$excerpt)." < a href='" .get_permalink($post->ID) ." ' class='".readmore."'>Read More";
echo $excerpt;
}
Usage: < ?php echo excerpt('15'); ?>


No comments:

Post a Comment