Created
June 27, 2012 05:14
-
-
Save manojsinghrwt/3001638 to your computer and use it in GitHub Desktop.
WordPress MS Framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* WP MS Framework 1.0 | |
* Version 1.0 | |
* Developed By Manoj Singh | |
* Note: The another supported file is under-development | |
*/ | |
/* | |
[1] get_wp_ms_excerpt($content,$size); | |
[2] get_wp_ms_category_id_by_name($cat_name); | |
[3] get_wp_ms_sub_category_name_by_id($parent_cat_name); | |
[4] get_wp_ms_vid_sc($atts, $content=null); | |
[5] get_wp_ms_video($post_ID); | |
[6] get_wp_ms_google_sound_by_ID($post_ID); | |
[7] get_wp_ms_google_sound_by_url($atts, $content=null); | |
[8] get_wp_ms_featured_img_url($postid); | |
[9] get_wp_ms_featured_img($postid); | |
[10] get_wp_ms_featured_img_url_use_size($post_ID, $size); | |
[11] get_wp_ms_featured_image_gallery($cat_ID); | |
[12] get_wp_ms_breadcrumbs(); | |
[13] get_wp_ms_latest_single_post($atts); | |
[14] get_wp_ms_isMobile(); | |
[15] get_wp_ms_author_archive(); | |
[16] get_wp_ms_author_meta(); | |
[17] get_wp_ms_category_link($cat_ID); | |
*/ | |
//////////////////////////////////////////////////////// | |
//////////////// Basic Support for Theme /////////////// | |
///////////////////////////////////////////////////////// | |
add_filter('widget_text', 'do_shortcode'); | |
function add_jquery(){ wp_enqueue_script( 'jquery' ); } | |
add_action('init', 'add_jquery'); | |
/////////////////////////////////////////////////////// | |
function add_more_buttons($buttons) { | |
$buttons[] = 'hr'; | |
$buttons[] = 'del'; | |
$buttons[] = 'sub'; | |
$buttons[] = 'sup'; | |
$buttons[] = 'fontselect'; | |
$buttons[] = 'fontsizeselect'; | |
$buttons[] = 'cleanup'; | |
$buttons[] = 'styleselect'; | |
return $buttons; | |
} | |
add_filter("mce_buttons_3", "add_more_buttons"); | |
/////////////////////////////////////////////////////// | |
function get_wp_ms_excerpt($content, $size){ | |
$content = str_replace(']]>', ']]>', $content); | |
$content = strip_tags($content, '<img />'); | |
$words = explode(' ', $content); | |
$content_out = ''; | |
for($l = 0; $l < $size; $l++) | |
{ | |
$content_out.= $words[$l]." "; | |
} | |
return $content_out; | |
} | |
/////////////////////////////////////////////////////// | |
//////////// Get the variable default post setting post per page////// | |
$post_per_page = get_option('posts_per_page'); | |
////////////////////////////////////////////////////// | |
function get_wp_ms_category_id_by_name($cat_name){ | |
$term = get_term_by('name', $cat_name, 'category'); | |
if($term==true){ | |
return $term->term_id; | |
} | |
else{ | |
echo '<pre>Category not found! Please Check spelling</pre>'; | |
} | |
} | |
function get_wp_ms_sub_category_name_by_id($parent_cat_name) | |
{ | |
$cat_ID = get_wp_ms_category_id_by_name($parent_cat_name); | |
$categories= get_categories('hide_empty=0&child_of='.$cat_ID); | |
//$out = '<h3 class="widget-title">'.$parent_cat_name.' Categories</h3>'; | |
//$out .= '<div id="cat_option_box">'; | |
//$out .= '<a class="parent_cat" href="'.get_category_link(get_wp_ms_category_id_by_name($parent_cat_name)).'">'.$parent_cat_name.'</a>'; | |
$out = '<ul class="sub_category">'; | |
foreach ($categories as $category) | |
{ | |
$out .= '<li class="cat_option" value="/category/archives/'.$category->category_nicename.'">'; | |
$out .='<a href="'.get_category_link(get_wp_ms_category_id_by_name($category->cat_name)).'">'; | |
$out .= $category->cat_name; | |
$out .= ' ('.$category->category_count.')'; | |
$out .='</a>'; | |
$out .= '</li>'; | |
} | |
$out .= '</ul>'; | |
// $out .= '</div>'; | |
return $out; | |
} | |
//////////////////////////////////////////////////////////// | |
///////////////// Video API By Manoj Singh //////////////// | |
//////////////////////////////////////////////////////////// | |
function get_wp_ms_vid_sc($atts, $content=null) { | |
extract( | |
shortcode_atts(array( | |
'site' => 'youtube', | |
'id' => '', | |
'w' => '600', | |
'h' => '370' | |
), $atts) | |
); | |
if ( $site == "youtube" ) { $src = 'http://www.youtube-nocookie.com/embed/'.$id; } | |
else if ( $site == "vimeo" ) { $src = 'http://player.vimeo.com/video/'.$id; } | |
else if ( $site == "dailymotion" ) { $src = 'http://www.dailymotion.com/embed/video/'.$id; } | |
else if ( $site == "yahoo" ) { $src = 'http://d.yimg.com/nl/vyc/site/player.html#vid='.$id; } | |
else if ( $site == "bliptv" ) { $src = 'http://a.blip.tv/scripts/shoggplayer.html#file=http://blip.tv/rss/flash/'.$id; } | |
else if ( $site == "veoh" ) { $src = 'http://www.veoh.com/static/swf/veoh/SPL.swf?videoAutoPlay=0&permalinkId='.$id; } | |
else if ( $site == "viddler" ) { $src = 'http://www.viddler.com/simple/'.$id; } | |
if ( $id != '' ) { | |
return '<iframe width="'.$w.'" height="'.$h.'" src="'.$src.'" class="vid iframe-'.$site.'"></iframe>'; | |
} | |
} | |
add_shortcode('vid','get_wp_ms_vid_sc'); | |
/////////////////////////////////////////////////////// | |
function get_wp_ms_video($post_ID) | |
{ | |
$video_code_key ='Video Code'; | |
$video_code = get_post_meta($post_ID, $video_code_key, true); | |
if($video_code){ | |
return '<div class="v_video_home">'.do_shortcode('[vid id="'.$video_code.'" site="vimeo" w="240" h="100"]').'</div>'; | |
} | |
} | |
////////////////////////////////////////////////////// | |
function get_wp_ms_google_sound_by_ID($post_ID){ | |
$w = 240; | |
$h = 100; | |
$sound_url_key ='Sound URL'; | |
$sound_url = get_post_meta($post_ID, $sound_url_key, true); | |
if($sound_url){ | |
return '<div class="ms_sound"><embed type="application/x-shockwave-flash" flashvars="audioUrl='.$sound_url.'" src="http://www.google.com/reader/ui/3523697345-audio-player.swf" width="'.$w.'" height="'.$h.'" quality=”best”></embed></div>'; | |
} | |
} | |
////////////////////////////////////////////////////// | |
function get_wp_ms_google_sound_by_url($atts, $content=null){ | |
extract( shortcode_atts(array( | |
'url' => '', | |
'w' => '240', | |
'h' => '100' | |
), $atts) | |
); | |
$sound_url = $url; | |
echo '<div class="ms_sound"><embed type="application/x-shockwave-flash" flashvars="audioUrl='.$sound_url.'" src="http://www.google.com/reader/ui/3523697345-audio-player.swf" width="'.$w.'" height="'.$h.'" quality=”best”></embed></div>'; | |
} | |
////////////////////////////////////////////////////// | |
////////////////// Featured Image /////////////////// | |
///////////////////////////////////////////////////// | |
function get_wp_ms_featured_img_url($postid) | |
{ | |
if(has_post_thumbnail($postid)) | |
{ | |
$img_url = wp_get_attachment_image_src(get_post_thumbnail_id($postid), 'large'); | |
return $img_url[0]; | |
} | |
else | |
{ | |
return '<div class="noimage">No Featured Image Set</div>'; | |
} | |
} | |
/////////////////////////////////////////////////////// | |
function get_wp_ms_featured_img($postid) | |
{ | |
if(has_post_thumbnail($postid)) | |
{ | |
$img_url = wp_get_attachment_image_src(get_post_thumbnail_id($postid), 'large'); | |
return '<img src="'.$img_url[0].'" />'; | |
} | |
else | |
{ | |
return 0; | |
} | |
} | |
//////////////////////////////////////////////////////// | |
function get_wp_ms_featured_img_url_use_size($post_id, $size){ | |
if(has_post_thumbnail($post_id)) | |
{ | |
if($size){ | |
$size = $size; | |
} | |
else | |
{ | |
$size ='medium'; | |
} | |
$img_url = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), $size); | |
return $img_url[0]; | |
} | |
} | |
//////////////////////////////////////////////////////// | |
function get_wp_ms_featured_image_gallery($cat_ID){ | |
$catID =get_wp_ms_category_id_by_name($cat_ID); | |
$posts = get_posts('width=50&showposts=10&cat='.$catID); | |
if($posts) | |
{ | |
foreach($posts as $post) | |
{ | |
$img_url = get_wp_ms_featured_img_url($post->ID); | |
if(!$img_url == 0){ | |
echo '<img alt="" src="'.$img_url.'" width="90" height="90"/>'; | |
} | |
else{ | |
} | |
} | |
} | |
} | |
/////////////////////////////////////////////////////// | |
////////////////* Breadcrumbs Code */////////////////// | |
/////////////////////////////////////////////////////// | |
function get_wp_ms_breadcrumbs() { | |
$showOnHome = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show | |
$delimiter = '»'; // delimiter between crumbs | |
$home = 'Home'; // text for the 'Home' link | |
$showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show | |
$before = '<span class="current">'; // tag before the current crumb | |
$after = '</span>'; // tag after the current crumb | |
global $post; | |
$homeLink = get_bloginfo('url'); | |
if (is_home() || is_front_page()) { | |
if ($showOnHome == 1) echo '<div id="crumbs"><a href="' . $homeLink . '">' . $home . '</a></div>'; | |
} else { | |
echo '<div id="crumbs"><a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' '; | |
if ( is_category() ) { | |
global $wp_query; | |
$cat_obj = $wp_query->get_queried_object(); | |
$thisCat = $cat_obj->term_id; | |
$thisCat = get_category($thisCat); | |
$parentCat = get_category($thisCat->parent); | |
if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' ')); | |
echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after; | |
} elseif ( is_day() ) { | |
echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' '; | |
echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' '; | |
echo $before . get_the_time('d') . $after; | |
} elseif ( is_month() ) { | |
echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' '; | |
echo $before . get_the_time('F') . $after; | |
} elseif ( is_year() ) { | |
echo $before . get_the_time('Y') . $after; | |
} elseif ( is_single() && !is_attachment() ) { | |
if ( get_post_type() != 'post' ) { | |
$post_type = get_post_type_object(get_post_type()); | |
$slug = $post_type->rewrite; | |
echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' '; | |
if ($showCurrent == 1) echo $before . get_the_title() . $after; | |
} else { | |
$cat = get_the_category(); $cat = $cat[0]; | |
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' '); | |
if ($showCurrent == 1) echo $before . get_the_title() . $after; | |
} | |
} elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) { | |
$post_type = get_post_type_object(get_post_type()); | |
echo $before . $post_type->labels->singular_name . $after; | |
} elseif ( is_attachment() ) { | |
$parent = get_post($post->post_parent); | |
$cat = get_the_category($parent->ID); $cat = $cat[0]; | |
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' '); | |
echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' '; | |
if ($showCurrent == 1) echo $before . get_the_title() . $after; | |
} elseif ( is_page() && !$post->post_parent ) { | |
if ($showCurrent == 1) echo $before . get_the_title() . $after; | |
} elseif ( is_page() && $post->post_parent ) { | |
$parent_id = $post->post_parent; | |
$breadcrumbs = array(); | |
while ($parent_id) { | |
$page = get_page($parent_id); | |
$breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>'; | |
$parent_id = $page->post_parent; | |
} | |
$breadcrumbs = array_reverse($breadcrumbs); | |
foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' '; | |
if ($showCurrent == 1) echo $before . get_the_title() . $after; | |
} elseif ( is_search() ) { | |
echo $before . 'Search results for "' . get_search_query() . '"' . $after; | |
} elseif ( is_tag() ) { | |
echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after; | |
} elseif ( is_author() ) { | |
global $author; | |
$userdata = get_userdata($author); | |
echo $before . 'Articles posted by ' . $userdata->display_name . $after; | |
} elseif ( is_404() ) { | |
echo $before . 'Error 404' . $after; | |
} | |
if ( get_query_var('paged') ) { | |
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' ('; | |
echo __('Page') . ' ' . get_query_var('paged'); | |
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')'; | |
} | |
echo '</div>'; | |
} | |
} | |
/////////////////////////////////////////////////////// | |
function get_wp_ms_latest_single_post($atts){ | |
extract(shortcode_atts( array('cat'=>''),$atts)); | |
$cat_ID = get_wp_ms_category_id_by_name($cat); | |
$posts = get_posts('width=50&showposts=1&cat='.$cat_ID); | |
if($posts) | |
{ | |
foreach($posts as $post) | |
{ | |
echo '<h4>'.$post->post_title.'</h4>'; | |
echo get_wp_ms_featured_img_url($post->ID); | |
echo '<div class="parasingle">'; | |
echo get_wp_ms_excerpt($post->post_content,30).'...</div>'; | |
echo '<br/> <a href="'.get_permalink($post->ID).'" class="readmore">Read More</a>'; | |
} | |
} | |
wp_reset_query(); | |
} | |
add_shortcode('single_post','get_wp_ms_latest_single_post'); | |
//////////////////////////////////////////////////////////// | |
/////////////// Detect Mobile Phones v. 1.0 //////////////// | |
//////////////////////////////////////////////////////////// | |
function get_wp_ms_isMobile() { | |
if(isset($_SERVER["HTTP_X_WAP_PROFILE"])) { return true; } /* Check the server headers to see if they're mobile friendly */ | |
if(preg_match("/wap\.|\.wap/i",$_SERVER["HTTP_ACCEPT"])) { return true; } /* If the http_accept header supports wap then it's a mobile too */ | |
/* Let's have a look at the user agent on the browser. If it contains any of the following, it's probably a mobile device.*/ | |
if(isset($_SERVER["HTTP_USER_AGENT"])){ | |
$user_agents = array("midp", "j2me", "avantg", "docomo", "novarra", "palmos", "palmsource", "240x320", "opwv", "chtml", "pda", "windows\ ce", "mmp\/", "blackberry", "mib\/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up\.b", "audio", "SIE\-", "SEC\-", "samsung", "HTC", "mot\-", "mitsu", "sagem", "sony", "alcatel", "lg", "erics", "vx", "NEC", "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "\d\d\di", "moto"); | |
foreach($user_agents as $user_string){ if(preg_match("/".$user_string."/i",$_SERVER["HTTP_USER_AGENT"])) { return true; } } | |
} | |
if(preg_match("/iphone/i",$_SERVER["HTTP_USER_AGENT"])) { return false; } /* Let's NOT return "mobile" if it's an iPhone, because the iPhone can render normal pages quite well. */ | |
// None of the above? Then it's probably not a mobile device. | |
return false; | |
} | |
/* | |
// Here's my code to which calls the above function | |
if (isMobile()) { | |
// if the function returned true, it's a mobile. | |
echo "mobile"; // delete this line in your code, and uncomment the next line | |
// header('Location: http://m.yoursite.com/'); // let's redirect the page to the mobile site | |
} | |
// if not, we're in a standard browser and our page can proceed as normally formatted for the web! | |
echo "web"; // delete this line in your code | |
*/ | |
//////////////////////////////////////////////////////////// | |
/////////////////////////////////////////// | |
////////////// Author ///////////////////// | |
////////////////////////////////////////// | |
function get_wp_ms_author_archive($author_ID) | |
{ | |
$curauth = get_userdata(get_query_var('author')); | |
$current_link = get_author_posts_url($curauth->ID, $curauth->display_name); | |
$autor_name = get_the_author_meta('user_nicename', $author_ID); | |
return $current_link.$autor_name; | |
} | |
function get_wp_ms_author_meta() | |
{ | |
global $wpdb; | |
//$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users WHERE display_name <> 'admin' ORDER BY display_name"); | |
$authors = $wpdb->get_results("SELECT * from $wpdb->users"); | |
echo '<ul class="blog_ul">'; | |
foreach ($authors as $author ) | |
{ | |
// echo '<pre>'; print_r($author); die(); | |
//echo $author->user_nicename.'<br/>'; | |
echo '<li>'; | |
echo '<div class="author_image">'.get_avatar( $author->user_email, $size = '42', $default = '<path_to_url>' ).'</div>'; | |
echo '<div class="author_info">'; | |
echo '<a href="'.get_wp_ms_author_archive($author->ID).'">'.get_user_meta($author->ID, 'first_name', true).' '.get_user_meta($author->ID, 'last_name', true).'</a>'; | |
echo '<br/>Latest Post<br/>'; | |
$args = array('author' => $author->ID,'showposts' => 1, 'caller_get_posts' => 1); | |
$query = new WP_Query($args); | |
if( $query->have_posts() ) | |
{ | |
while ($query->have_posts()) : $query->the_post(); | |
?> | |
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> | |
<?php //the_content(); | |
endwhile; | |
} | |
echo '</div>'; | |
echo '</li>'; | |
//echo $author->display_name; | |
} | |
echo '</ul>'; | |
} | |
///////////////////////////////////////////////////////// | |
////////////////// Category //////////////////////////// | |
//////////////////////////////////////////////////////// | |
function get_wp_ms_category_link($cat_ID){ | |
$link = get_category_link(get_wp_ms_category_id_by_name($cat_ID)); | |
return $link; | |
} | |
//////////////////////////////////////////////////////// | |
/////////////////// Social Media ////////////////////// | |
/////////////////////////////////////////////////////// | |
add_shortcode('facebook','facebook'); | |
function facebook($atts){ extract( shortcode_atts( array('link' => ''), $atts )); return '<a class="facebook social_network" href="' . $link . '" target="_new">Join us facebook </a>'; } | |
add_shortcode('twitter','twitter'); | |
function twitter($atts){ extract( shortcode_atts(array('link' => ''), $atts )); return '<a class="twitter social_network" href="' . $link . '" target="_new">Fallow us on twitter </a>'; } | |
add_shortcode('youtube','youtube'); | |
function youtube($atts) { extract( shortcode_atts( array( 'link' => ''), $atts)); return '<a class="youtube social_network" href="' . $link . '" target="_new"> </a>';} | |
add_shortcode('rss','rss'); | |
function rss(){ $rsslink = get_bloginfo('rss2_url','Display'); return '<a class="rss social_network" href="' .$rsslink. '" target="_new">Subscribe to our blog </a>'; } | |
add_shortcode('contact','contact'); | |
function contact($atts){ extract( shortcode_atts(array('link' => ''), $atts )); return '<a class="contact social_network" href="' . $link . '">Contact us </a>'; } | |
////////////////////////////////////////////////////////// | |
function get_wp_ms_twitter(){ | |
?> | |
<script type="text/javascript"> | |
new TWTR.Widget({ | |
version: 2, | |
type: 'profile', | |
rpp: 5, interval: 6000, width: 400, height: 600, | |
theme: { | |
shell: { | |
background: '#ffffff', | |
color: '#000000' | |
}, | |
tweets: { | |
background: '#ffffff', | |
color: '#000000', | |
links: '#1725bf' | |
} | |
}, | |
features: { | |
scrollbar: false, | |
loop: false, | |
live: false, | |
hashtags: true, | |
timestamp: true, | |
avatars: false, | |
behavior: 'all' | |
} | |
}).render().setUser('<?php echo $tweetuser; ?>').start(); | |
</script> | |
<?php | |
} | |
//////////////////////////////////////////////////// | |
function social_option( $contactmethods ) { | |
$contactmethods['twitter'] = 'Twitter'; | |
$contactmethods['facebook'] = 'Facebook'; | |
return $contactmethods; | |
} | |
add_filter('user_contactmethods','social_option',10,1); /* <?php echo $curauth->twitter; ?> //You can then call the fields in your author.php template by adding the code */ | |
add_filter('user_contactmethods','hide_profile_fields',10,1); /*Remove Author Profile Fields //Profile->Contact info */ | |
//////////////////////////////////////////////////// | |
function hide_wp_ms_profile_fields( $contactmethods ) { | |
unset($contactmethods['aim']); | |
unset($contactmethods['jabber']); | |
unset($contactmethods['yim']); | |
return $contactmethods; | |
} | |
add_filter('user_contactmethods','hide_wp_ms_profile_fields',10,1); /*Remove Author Profile Fields //Profile->Contact info */ | |
///////////////////////////////////////////////////// | |
$tweetuser = get_the_author_meta( 'twitter', 1 ); | |
///////////////////////////////////////////////////// | |
function my_scripts_method() { | |
wp_enqueue_script( | |
'colorbox', | |
get_template_directory_uri() . '/js/jquery.colorbox.js', | |
array('jquery') | |
); | |
wp_enqueue_script( | |
'nivoslider', | |
get_template_directory_uri() . '/js/jquery.nivo.slider.js', | |
array('jquery') | |
); | |
wp_enqueue_script( | |
'organictabs', | |
get_template_directory_uri() . '/js/organictabs.jquery.js', | |
array('jquery') | |
); | |
wp_enqueue_script( | |
'loadmask', | |
get_template_directory_uri() . '/js/jquery.loadmask.min.js', | |
array('jquery') | |
); | |
} | |
add_action('wp_enqueue_scripts', 'my_scripts_method'); | |
///////////////////////////////////////////////////////// | |
function theme_styles() | |
{ | |
wp_register_style( 'nivoslider', | |
get_template_directory_uri() . '/css/nivo-slider.css' ); | |
wp_enqueue_style( 'nivoslider' ); | |
wp_register_style( 'colorbox', | |
get_template_directory_uri() . '/css/colorbox.css' ); | |
wp_enqueue_style( 'colorbox' ); | |
wp_register_style( 'loadmask', | |
get_template_directory_uri() . '/css/jquery.loadmask.css' ); | |
wp_enqueue_style( 'loadmask' ); | |
} | |
add_action('wp_print_styles', 'theme_styles'); | |
///////////////////////////////////////////////////////// | |
function twentyten_widgets_init() { | |
register_sidebar( array( | |
'name' => __( 'New Widget Area', 'twentyten' ), | |
'id' => 'new-widget-area', | |
'description' => __( 'The new widget area', 'twentyten' ), | |
'before_widget' => '<li id="%1$s" class="widget-container %2$s">', | |
'after_widget' => '</li>', | |
'before_title' => '<h2 class="widget-title">', | |
'after_title' => '</h2>', | |
) ); | |
} | |
add_action( 'widgets_init', 'twentyten_widgets_init' ); | |
//////////////////////////////////////////////////////////////// | |
// Run Loop out side of wordpress | |
// Include WordPress | |
define('WP_USE_THEMES', false); | |
require('/server/path/to/your/wordpress/site/htdocs/blog/wp-blog-header.php'); | |
query_posts('showposts=1'); | |
//////////////////////////////////////// | |
//////////// Post Date Convert ////////// | |
$post_date . mysql2date('j M Y', $post->post_date); | |
///////////////////////////////////////////////// | |
echo '<div class="dateComent">', | |
'<div class="postedby">Posted by : <span class="authorNmae">',$author = get_the_author(),'</span></div>', | |
'<div class="commentSec">', | |
'<span class="comments-link">Comments <span class="numberSec">',$post->comment_count,'</span></span> ', | |
'</div>', | |
'<div class="postdate">',$post_date . mysql2date(' M j Y', $post->post_date),'</div></div>'; | |
//////////////////////////////////////////////////// | |
/// /%category%/%postname%/ | |
////////////////////////////////////////////////// | |
///////Working with multiple specific pages using array (page id) | |
$page_id_arr = array(516,522,510,520,508,506,518, 514, 504); /* Pgae id pass to array */ | |
foreach($page_id_arr as $page_id) | |
{ | |
$page_content = get_post($page_id); | |
$content = $page_content->post_content; | |
$content = str_replace(']]>', ']]>', $content); | |
$content = strip_tags($content, '<img />'); | |
$content_length = 70; | |
$words = explode(' ', $content); | |
$newContent = ''; | |
for($l = 0; $l<$content_length; $l++) | |
{ | |
$newContent .= $words[$l]." "; | |
} | |
$newContent = "<div id='page".$k++."'><span><h3>".$page_content->post_title."</h3><p>".$newContent .= "</p><a class='msButton' href='".get_permalink($page_content->ID)."'>"."#".$l=($k-1)." ".$page_content->post_title."</a></span></div>"; | |
echo $newContent; | |
} | |
wp_reset_query(); | |
//////////////////////////////////////////// | |
////////////Display Excerpts of Child Pages with a Shortcode | |
function subpage_peek() { | |
global $post; | |
//query subpages | |
$args = array( | |
'post_parent' => $post->ID, | |
'post_type' => 'page' | |
); | |
$subpages = new WP_query($args); | |
// create output | |
if ($subpages->have_posts()) : | |
$output = '<ul>'; | |
while ($subpages->have_posts()) : $subpages->the_post(); | |
$output .= '<li><strong><a href="'.get_permalink().'">'.get_the_title().'</a></strong> | |
<p>'.get_the_excerpt().'<br /> | |
<a href="'.get_permalink().'">Continue Reading →</a></p></li>'; | |
endwhile; | |
$output .= '</ul>'; | |
else : | |
//$output = '<p>No subpages found.</p>'; | |
endif; | |
// reset the query | |
wp_reset_postdata(); | |
// return something | |
return $output; | |
} | |
add_shortcode('subpage', 'subpage_peek'); | |
?> | |
<?php flush(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment