Archive for January, 2013

Line 13 – 16 in content.php of the twentyeleven theme. Line 16 places the word Featured on sticky posts.

13 <?php if ( is_sticky() ) : ?>
14 ........
15 .........
16 <h3><?php _e( 'Featured', 'twentyeleven' ); ?></h3>

open function.php

register_sidebar( array(
‘name’ => __( ‘Copyright’, ‘twentyeleven’ ),
‘id’ => ‘sidebar-4’,
‘description’ => __( ‘An optional widget area for your site footer’, ‘twentyeleven’ ),
‘before_widget’ => ‘<aside id=”%1$s”>’,
‘after_widget’ => “</aside>”,
‘before_title’ => ‘<h3>’,
‘after_title’ => ‘</h3>’,
) );

register_sidebar( array(
‘name’ => __( ‘Copyright’, ‘twentyeleven’ ),
‘id’ => ‘sidebar-4’,
‘description’ => __( ‘An optional widget area for your site footer’, ‘twentyeleven’ ),
‘before_widget’ => ”,
‘after_widget’ => “”,
‘before_title’ => ”,
‘after_title’ => ”,
) );

<?php
if ( !function_exists(‘dynamic_sidebar’)|| !dynamic_sidebar(‘sidebar-4’) ) : ?>
<?php endif;
?>

 

Create Custom post type in wordpress

Posted: January 30, 2013 in Wordpress

Paste this code function.php

function post_type_discog() {

register_post_type(‘discography’,
array(
‘labels’ => array(
‘name’ => __( ‘Discography’ ),
‘singular_name’ => __( ‘Discography’ ),
‘add_new’ => __( ‘Add New’ ),
‘add_new_item’ => __( ‘Add New Discography’ ),
‘edit’ => __( ‘Edit’ ),
‘edit_item’ => __( ‘Edit Discography’ ),
‘new_item’ => __( ‘New Discography’ ),
‘view’ => __( ‘View Discography’ ),
‘view_item’ => __( ‘View Discography’ ),
‘search_items’ => __( ‘Search Discographys’ ),
‘not_found’ => __( ‘No Discographys found’ ),
‘not_found_in_trash’ => __( ‘No Discographys found in Trash’ ),
‘parent’ => __( ‘Parent Discography’ ),
),
‘public’ => true,
‘show_ui’ => true,
‘exclude_from_search’ => true,
‘hierarchical’ => true,
‘supports’ => array( ‘title’, ‘editor’, ‘thumbnail’ ),
‘query_var’ => true
)
);
}
add_action(‘init’, ‘post_type_discog’);

add_action( ‘init’, ‘create_discog_taxonomies’, 0 );

function create_discog_taxonomies()
{
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
‘name’ => _x( ‘Recordings’, ‘taxonomy general name’ ),
‘singular_name’ => _x( ‘Recording’, ‘taxonomy singular name’ ),
‘search_items’ =>  __( ‘Search Recordings’ ),
‘popular_items’ => __( ‘Popular Recordings’ ),
‘all_items’ => __( ‘All Recordings’ ),
‘parent_item’ => __( ‘Parent Recording’ ),
‘parent_item_colon’ => __( ‘Parent Recording:’ ),
‘edit_item’ => __( ‘Edit Recording’ ),
‘update_item’ => __( ‘Update Recording’ ),
‘add_new_item’ => __( ‘Add New Recording’ ),
‘new_item_name’ => __( ‘New Recording Name’ ),
);
register_taxonomy(‘recordings’,array(‘discography’), array(
‘hierarchical’ => true,
‘labels’ => $labels,
‘show_ui’ => true,
‘query_var’ => true,
‘rewrite’ => array( ‘slug’ => ‘recordings’ ),
));
}

<?php
/**
* Template Name: Sidebar Template
* Description: A Page Template that adds a sidebar to pages
*
* @package WordPress
* @subpackage Twenty_Eleven
* @since Twenty Eleven 1.0
*/
get_header(); ?>

<div id=”figure”>
<?php $sticky = get_option( ‘sticky_posts’ );
$args = array(
‘posts_per_page’ => 1,
‘post__in’  => get_option( ‘sticky_posts’ ),
‘ignore_sticky_posts’ => 1

);

if ( !empty($sticky) ):
// has sticky posts
query_posts($args);

$stickyPosts = new WP_query();
$stickyPosts->query($args);
if ( $stickyPosts->have_posts() ):

while ( $stickyPosts->have_posts() ) : $stickyPosts->the_post();
?>

<div>

<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘single-post-thumbnail’ ); ?>

<img src=”<?php echo $image[0]; ?>”  height=”256″ width=”430″/> // Featured image

<div>

<h1><?php the_title(); ?></h1>
<p> <?php echo substr(strip_tags($post->post_content), 0, 500);?></p>
<a  href=”<?php echo get_permalink($recent[“ID”]);?>”>read more…</a>

<?php
endwhile; //end loop for sticky posts
wp_reset_query();
endif;
endif;
?>