رفتن به مطلب

قرار گرفتن خودکار تصویر مطالب به عنوان تصویر شاخص


پست های پیشنهاد شده

سلام خشته نباشین

راهی هست که بشه تصویر یک مطلب به صورت خودکار به عنوان تصویر شاخص همون مطلب هم قرار بگیره؟

لینک به ارسال

سلام

میتونید از افزونه Auto Post Thumbnail استفاده کنید که اولین تصویر رو به عنوان تصویر شاخص انتخاب میکنه.

اگر هم نمی خواهید از افزونه استفاده کنید اینجا رو نگا کنید:

http://forum.wp-pars...-تصویر-هر-مطلب/

ویرایش شده توسط ممد
لینک به ارسال

این کد در فانکشن


function get_first_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}

این کد در صفحه


<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >
<img src="<?php echo get_first_image();?>" alt="<?php the_title(); ?>" class="thumbnail">
</a>

لینک به ارسال

ببخشید منظورتون کدوم صفحه است؟

مهم نیست کجای فانکشن قرار بدم؟

آخر کدهای فانکشن قبل از این علامت <? قرار بدید

منظور از صفحه هم جایی هست که میخواهید اون تصویر نمایش داده بشه

لینک به ارسال

من میخوام برای همه مطالبم تصویر شاخص به طور خودکار قرار بگیره.

تو همه صفحه ها باید نمایش داده بشه دیگه!!! اون وقت اون صفحه کجا هست؟ تو قسمت صفحه اصلی باید بزارم؟

لینک به ارسال

این فانکشن

<?php

if ( function_exists('register_sidebar') )

register_sidebar(array(

'name' => 'Right',

'before_widget' => '',

'before_title' => '<div class="wig-up"><h3>',

'after_title' => '</h3></div><div class="side-body">',

'after_widget' => '</div>',

));

register_sidebar(array(

'name' => 'Left',

'before_widget' => '',

'before_title' => '<div class="wig-up"><h3>',

'after_title' => '</h3></div><div class="side-body">',

'after_widget' => '</div>',

));

function dimox_breadcrumbs() {

$delimiter = '»';

$home = 'خانه'; // text for the 'Home' link

$before = '<span>'; // tag before the current crumb

$after = '</span>'; // tag after the current crumb

if ( !is_home() && !is_front_page() || is_paged() ) {

echo '<div id="crumbs">';

global $post;

$homeLink = get_bloginfo('url');

echo '<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 . '"' . 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 . ' ';

echo $before . get_the_title() . $after;

} else {

$cat = get_the_category(); $cat = $cat[0];

echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');

echo $before . get_the_title() . $after;

}

} elseif ( !is_single() && !is_page() && get_post_type() != 'post' ) {

$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 . ' ';

echo $before . get_the_title() . $after;

} elseif ( is_page() && !$post->post_parent ) {

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 . ' ';

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>';

}

}

///****** Adding Theme Options *****///

require_once( 'option/option.php' );

//Activate the Link Manager built in to the WordPress admin

add_filter( 'pre_option_link_manager_enabled', '__return_true' );

//Deactive admin bar

add_filter( 'show_admin_bar', '__return_false' );

remove_action( 'personal_options', '_admin_bar_preferences' );

//Add Thumbnails//

if (function_exists('add_theme_support')) {

add_theme_support( 'post-thumbnails' );

}

///***** get the first image attached to the current post *****///

function catch_that_image() {

global $post, $posts;

$first_img = '';

ob_start();

ob_end_clean();

$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);

$first_img = $matches [1] [0];

if(empty($first_img)){ //Defines a default image

$first_img = "/images/default.jpg";

}

return $first_img;

}

///********** popular post **********////

function popularPosts($num) {

global $wpdb;

$posts = $wpdb->get_results("SELECT comment_count, ID, post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , $num");

foreach ($posts as $post) {

setup_postdata($post);

$id = $post->ID;

$title = $post->post_title;

$count = $post->comment_count;

if ($count != 0) {

$popular .= '<li>';

$popular .= '<a href="' . get_permalink($id) . '" title="' . $title . '">'

. $title . '</a> ';

$popular .= '</li>';

}

}

return $popular;

}

///************* Site counts ************///

function post_count_func( $atts ) {

$total = wp_count_posts()->publish;

return $total;

}

add_shortcode( 'postcount', 'post_count_func' );

add_shortcode( 'post-count', 'post_count_func' );

function comment_count_func ( $atts ) {

$total = wp_count_comments()->approved;

return $total;

}

add_shortcode( 'commentcount', 'comment_count_func' );

add_shortcode( 'comment-count', 'comment_count_func' );

function page_count_func ( $atts ) {

$total = wp_count_posts('page')->publish;

return $total;

}

add_shortcode( 'pagecount', 'page_count_func' );

add_shortcode( 'page-count', 'page_count_func' );

function word_count_func() {

global $wpdb;

$now = gmdate("Y-m-d H:i:s",time());

$query = "SELECT post_content FROM $wpdb->posts WHERE post_status = 'publish' AND post_date < '$now'";

$words = $wpdb->get_results($query);

if ($words) {

foreach ($words as $word) {

$post = strip_tags($word->post_content);

$post = explode(' ', $post);

$count = count($post);

$total = $count + $oldcount;

$oldcount = $total;

}

}

else {

$total=0;

}

return number_format($total);

}

add_shortcode( 'totalwordcount', 'word_count_func' );

add_shortcode( 'total-word-count', 'word_count_func' );

add_shortcode( 'blogwordcount', 'word_count_func' );

add_shortcode( 'blog-word-count', 'word_count_func' );

///************** User Ip *************///

function display_user_ip()

{

$user_ip = $_SERVER['REMOTE_ADDR'];

return $user_ip;

}

add_shortcode('user_ip', 'display_user_ip');

///************ Like Post ************///

function likeThis($post_id,$action = 'get') {

if(!is_numeric($post_id)) {

error_log("خطا : مقدار عددي براي post_id ارسال نشده است");

return;

}

switch($action) {

case 'get':

$data = get_post_meta($post_id, '_likes');

if(!is_numeric($data[0])) {

$data[0] = 0;

add_post_meta($post_id, '_likes', '0', true);

}

return $data[0];

break;

case 'update':

if(isset($_COOKIE["like_" . $post_id])) {

return;

}

$currentValue = get_post_meta($post_id, '_likes');

if(!is_numeric($currentValue[0])) {

$currentValue[0] = 0;

add_post_meta($post_id, '_likes', '1', true);

}

$currentValue[0]++;

update_post_meta($post_id, '_likes', $currentValue[0]);

setcookie("like_" . $post_id, $post_id,time()+(60*60*24*365));

break;

}

}

function post_likes($post_id) {

$likes = likeThis($post_id);

$who = ' بار پسنديده شده است ';

if($likes == 1) {

$who = ' بار پسنديده شده است ';

}

if(isset($_COOKIE["like_" . $post_id])) {

print '<a href="#" class="likeThis done" id="like-'.$post_id.'">'.$likes.$who.'</a>';

return;

}

print '<a href="#" class="likeThis" id="like-'.$post_id.'">'.$likes.$who.'</a>';

}

function setUpPostLikes($post_id) {

if(!is_numeric($post_id)) {

error_log("خطا : مقدار عددي براي post_id ارسال نشده است");

return;

}

add_post_meta($post_id, '_likes', '0', true);

}

function checkHeaders() {

if(isset($_POST["likepost"])) {

likeThis($_POST["likepost"],'update');

}

}

function jsIncludes() {

wp_enqueue_script('jquery');

wp_register_script('likescript',

get_template_directory_uri(). '/js/likescript.js' );

wp_enqueue_script('likescript',array('jquery'));

}

add_action ('publish_post', 'setUpPostLikes');

add_action ('init', 'checkHeaders');

add_action ('get_header', 'jsIncludes');

?>

اینم index.php

<?php get_header();?>

<div class="page">

<?php include (TEMPLATEPATH . '/rsidebar.php'); ?>

<div class="postside">

<div class="pm">

<div class="pm-text">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_pm")) ; ?>

</div>

</div>

<?php if (get_option('download_ads_show')): ?>

<div class="ads" style="height:auto;">

<div class="ads-one" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner1")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner2")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner3")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner4")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner5")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner6")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner7")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner8")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner9")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner10")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner11")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner12")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner13")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner14")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner15")) ; ?>

</div>

</div>

<?php endif; ?>

<!-- Slider -->

<?php include (TEMPLATEPATH . '/slider.php'); ?>

<!-- //Slider -->

<!-- Post -->

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

<div class="posth" id="post-<?php the_ID(); ?>">

<div class="thm">

<?php if (has_post_thumbnail()) { the_post_thumbnail('news_thumbs', array('alt' => get_the_title() ));} else { ?>

<img src="<?php bloginfo('template_directory'); ?>/images/thm.png" title="<?php the_title(); ?>" alt="<?php the_title(); ?>" />

<?php } ?>

</div>

<h2><?php the_title(); ?></h2></div>

<div class="postb">

<div class="Info">

<div class="date">تاریخ : <?php the_time('l، j F Y') ?></div>

<div class="views"><?php if(function_exists('the_views')) { the_views(); } ?></div>

<div class="com"><?php comments_number('0','1','%'); ?>دیدگاه</div>

<div class="authors">نوشته:<?php the_author(); ?></div>

</div>

<div class="news">

<?php the_content(__('')); ?>

</div>

<div class="likes">

<?php post_likes(get_the_ID()); ?>

</div>

<div class="Info">

موضوع : <?php the_category(', ') ?>

<a class="continue" target="_blank" href="<?php the_permalink(); ?>">ادامه ی مطلب</a>

</div>

</div>

<?php endwhile; ?>

<?php endif; ?>

<!-- //Post -->

<div class="pagination">

<?php global $SMTheme; ?>

<?php

global $wp_query;

$big = 999999999;

echo paginate_links( array(

'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),

'format' => '?paged=%#%',

'current' => max( 1, get_query_var('paged') ),

'total' => $wp_query->max_num_pages

) );

?>

</div>

</div>

<?php include (TEMPLATEPATH . '/lsidebar.php'); ?>

<?php get_footer(); ?>

</body>

</html>

لینک به ارسال

index.php

<?php get_header();?>

<div class="page">

<?php include (TEMPLATEPATH . '/rsidebar.php'); ?>

<div class="postside">

<div class="pm">

<div class="pm-text">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_pm")) ; ?>

</div>

</div>

<?php if (get_option('download_ads_show')): ?>

<div class="ads" style="height:auto;">

<div class="ads-one" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner1")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner2")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner3")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner4")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner5")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner6")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner7")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner8")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner9")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner10")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner11")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner12")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner13")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner14")) ; ?>

</div>

<div class="ads-two" style="height: auto;">

<?php echo $opname = str_replace(array('\"',"\'"),array('"',"'"),get_option("download_banner15")) ; ?>

</div>

</div>

<?php endif; ?>

<!-- Slider -->

<?php include (TEMPLATEPATH . '/slider.php'); ?>

<!-- //Slider -->

<!-- Post -->

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

<div class="posth" id="post-<?php the_ID(); ?>">

<div class="thm">

<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >

<img src="<?php echo get_first_image();?>" alt="<?php the_title(); ?>" class="thumbnail">

</a>

</div>

<h2><?php the_title(); ?></h2></div>

<div class="postb">

<div class="Info">

<div class="date">تاریخ : <?php the_time('l، j F Y') ?></div>

<div class="views"><?php if(function_exists('the_views')) { the_views(); } ?></div>

<div class="com"><?php comments_number('0','1','%'); ?>دیدگاه</div>

<div class="authors">نوشته:<?php the_author(); ?></div>

</div>

<div class="news">

<?php the_content(__('')); ?>

</div>

<div class="likes">

<?php post_likes(get_the_ID()); ?>

</div>

<div class="Info">

موضوع : <?php the_category(', ') ?>

<a class="continue" target="_blank" href="<?php the_permalink(); ?>">ادامه ی مطلب</a>

</div>

</div>

<?php endwhile; ?>

<?php endif; ?>

<!-- //Post -->

<div class="pagination">

<?php global $SMTheme; ?>

<?php

global $wp_query;

$big = 999999999;

echo paginate_links( array(

'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),

'format' => '?paged=%#%',

'current' => max( 1, get_query_var('paged') ),

'total' => $wp_query->max_num_pages

) );

?>

</div>

</div>

<?php include (TEMPLATEPATH . '/lsidebar.php'); ?>

<?php get_footer(); ?>

</body>

</html>

فانکشن

<?php

if ( function_exists('register_sidebar') )

register_sidebar(array(

'name' => 'Right',

'before_widget' => '',

'before_title' => '<div class="wig-up"><h3>',

'after_title' => '</h3></div><div class="side-body">',

'after_widget' => '</div>',

));

register_sidebar(array(

'name' => 'Left',

'before_widget' => '',

'before_title' => '<div class="wig-up"><h3>',

'after_title' => '</h3></div><div class="side-body">',

'after_widget' => '</div>',

));

function dimox_breadcrumbs() {

$delimiter = '»';

$home = 'خانه'; // text for the 'Home' link

$before = '<span>'; // tag before the current crumb

$after = '</span>'; // tag after the current crumb

if ( !is_home() && !is_front_page() || is_paged() ) {

echo '<div id="crumbs">';

global $post;

$homeLink = get_bloginfo('url');

echo '<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 . '"' . 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 . ' ';

echo $before . get_the_title() . $after;

} else {

$cat = get_the_category(); $cat = $cat[0];

echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');

echo $before . get_the_title() . $after;

}

} elseif ( !is_single() && !is_page() && get_post_type() != 'post' ) {

$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 . ' ';

echo $before . get_the_title() . $after;

} elseif ( is_page() && !$post->post_parent ) {

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 . ' ';

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>';

}

}

///****** Adding Theme Options *****///

require_once( 'option/option.php' );

//Activate the Link Manager built in to the WordPress admin

add_filter( 'pre_option_link_manager_enabled', '__return_true' );

//Deactive admin bar

add_filter( 'show_admin_bar', '__return_false' );

remove_action( 'personal_options', '_admin_bar_preferences' );

//Add Thumbnails//

if (function_exists('add_theme_support')) {

add_theme_support( 'post-thumbnails' );

}

///***** get the first image attached to the current post *****///

function catch_that_image() {

global $post, $posts;

$first_img = '';

ob_start();

ob_end_clean();

$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);

$first_img = $matches [1] [0];

if(empty($first_img)){ //Defines a default image

$first_img = "/images/default.jpg";

}

return $first_img;

}

///********** popular post **********////

function popularPosts($num) {

global $wpdb;

$posts = $wpdb->get_results("SELECT comment_count, ID, post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , $num");

foreach ($posts as $post) {

setup_postdata($post);

$id = $post->ID;

$title = $post->post_title;

$count = $post->comment_count;

if ($count != 0) {

$popular .= '<li>';

$popular .= '<a href="' . get_permalink($id) . '" title="' . $title . '">'

. $title . '</a> ';

$popular .= '</li>';

}

}

return $popular;

}

///************* Site counts ************///

function post_count_func( $atts ) {

$total = wp_count_posts()->publish;

return $total;

}

add_shortcode( 'postcount', 'post_count_func' );

add_shortcode( 'post-count', 'post_count_func' );

function comment_count_func ( $atts ) {

$total = wp_count_comments()->approved;

return $total;

}

add_shortcode( 'commentcount', 'comment_count_func' );

add_shortcode( 'comment-count', 'comment_count_func' );

function page_count_func ( $atts ) {

$total = wp_count_posts('page')->publish;

return $total;

}

add_shortcode( 'pagecount', 'page_count_func' );

add_shortcode( 'page-count', 'page_count_func' );

function word_count_func() {

global $wpdb;

$now = gmdate("Y-m-d H:i:s",time());

$query = "SELECT post_content FROM $wpdb->posts WHERE post_status = 'publish' AND post_date < '$now'";

$words = $wpdb->get_results($query);

if ($words) {

foreach ($words as $word) {

$post = strip_tags($word->post_content);

$post = explode(' ', $post);

$count = count($post);

$total = $count + $oldcount;

$oldcount = $total;

}

}

else {

$total=0;

}

return number_format($total);

}

add_shortcode( 'totalwordcount', 'word_count_func' );

add_shortcode( 'total-word-count', 'word_count_func' );

add_shortcode( 'blogwordcount', 'word_count_func' );

add_shortcode( 'blog-word-count', 'word_count_func' );

///************** User Ip *************///

function display_user_ip()

{

$user_ip = $_SERVER['REMOTE_ADDR'];

return $user_ip;

}

add_shortcode('user_ip', 'display_user_ip');

///************ Like Post ************///

function likeThis($post_id,$action = 'get') {

if(!is_numeric($post_id)) {

error_log("خطا : مقدار عددي براي post_id ارسال نشده است");

return;

}

switch($action) {

case 'get':

$data = get_post_meta($post_id, '_likes');

if(!is_numeric($data[0])) {

$data[0] = 0;

add_post_meta($post_id, '_likes', '0', true);

}

return $data[0];

break;

case 'update':

if(isset($_COOKIE["like_" . $post_id])) {

return;

}

$currentValue = get_post_meta($post_id, '_likes');

if(!is_numeric($currentValue[0])) {

$currentValue[0] = 0;

add_post_meta($post_id, '_likes', '1', true);

}

$currentValue[0]++;

update_post_meta($post_id, '_likes', $currentValue[0]);

setcookie("like_" . $post_id, $post_id,time()+(60*60*24*365));

break;

}

}

function post_likes($post_id) {

$likes = likeThis($post_id);

$who = ' بار پسنديده شده است ';

if($likes == 1) {

$who = ' بار پسنديده شده است ';

}

if(isset($_COOKIE["like_" . $post_id])) {

print '<a href="#" class="likeThis done" id="like-'.$post_id.'">'.$likes.$who.'</a>';

return;

}

print '<a href="#" class="likeThis" id="like-'.$post_id.'">'.$likes.$who.'</a>';

}

function setUpPostLikes($post_id) {

if(!is_numeric($post_id)) {

error_log("خطا : مقدار عددي براي post_id ارسال نشده است");

return;

}

add_post_meta($post_id, '_likes', '0', true);

}

function checkHeaders() {

if(isset($_POST["likepost"])) {

likeThis($_POST["likepost"],'update');

}

}

function jsIncludes() {

wp_enqueue_script('jquery');

wp_register_script('likescript',

get_template_directory_uri(). '/js/likescript.js' );

wp_enqueue_script('likescript',array('jquery'));

}

add_action ('publish_post', 'setUpPostLikes');

add_action ('init', 'checkHeaders');

add_action ('get_header', 'jsIncludes');

function get_first_image() {

global $post, $posts;

$first_img = '';

ob_start();

ob_end_clean();

$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);

$first_img = $matches [1] [0];

if(empty($first_img)){ //Defines a default image

$first_img = "/images/default.jpg";

}

return $first_img;

}

?>

لینک به ارسال

خیلی ممنون.

قبلیا رو کلا پاک کنم دیگه؟

راستی مطالب گذشته هم تصویر شاخص میگیرن؟

ویرایش شده توسط destroyer
لینک به ارسال

شما هرجا تصویرشاخص استفاده کردید تابع زیر جای تابع تصویر قرار بدید:


<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" >
<img src="<?php echo get_first_image();?>" alt="<?php the_title(); ?>" class="thumbnail">
</a>

لینک به ارسال

این قسمت آخر رو متوجه نشدم چی گفتید.

ولی کدها رو جایگزین کردم درست درست بود. مطالب قبلی هم تصویر شاخص دارن. دستتون درد نکنه

لینک به ارسال

ببینید شما هرجایی تابعی مشابه


the_post_thumbnail

بود بردارید و کد بالا که دادیم جایگزین کنید

لینک به ارسال

درود.

جناب destroyer شما از قالب بنده استفاده می کنید تمامی این کدها از قبل تو فانکشن و توی قالب گذاشته بودم.اگه تو همون تاپیک قالب بنده می گفتید که می خواید اون کادر کوچیک رو ویرایش کنید من همونجا راهنمایی می کردم که چه چیزی رو جایگزین کنید.اما شما سوالتون این بود که چطور برای پست ها تصاویر شاخص ایجاد بشه اونم از عکس مطالب. ببینید شما الان با این کد فقط دارید اولین عکس مطلبتون رو به عنوان تصویر شاخص در نظر می گیرید.فقط کد داره این تصویر رو به عنوان تصویر شاخص در نظر می گیره.از اون تصویر مطلب تصویر شاخص درست نمی کنه که همیشه موجود باشه با یک تعویض قالب مجددا باید کدها رو وارد کنید چون تصویر شاخصی در عمل ایجاد نشده!!!

ویرایش شده توسط افشیــــــن
لینک به ارسال

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع ...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...