رفتن به مطلب

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


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

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

twentythirteen-1.zip

لینک به ارسال

سلام

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

2. برای تبدیل اولین تصویر مطلب به تصویر شاخص این کد را به فایل functions.php اضافه کنید.


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);
if(!empty($matches [1] [0])) {
$output = '<img src="'.$matches [1] [0].'" alt="">';
}
}

و این کد را هم به محل نمایش


<a href="<?php the_permalink();?>" title="<?php the_title_attribute('echo=1');?>" rel="bookmark" class="thumbnail"><?php echo get_first_image();?></a>

3. برای کادر و استایل های دیگه هم در فایل style.css به کلاس thumbnail استایل دهید

لینک به ارسال


<?php
/**
* The main template file
*
* This is the most generic template file in a WordPress theme and one of the
* two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* For example, it puts together the home page when no home.php file exists.
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
* @subpackage Twenty_Thirteen
* @since Twenty Thirteen 1.0
*/
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php if ( have_posts() ) : ?>
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php twentythirteen_paging_nav(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

عزیز این فایل ایندکس منه میشه بگی کجاشو فراخونی کنم؟

لینک به ارسال

داخل فایل content.php جایگزین


<?php
// Post thumbnail.
twentyfifteen_post_thumbnail();
?>

کنید

کد فانکشن را هم تغییر بدید به


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);
if(!empty($matches [1] [0])) {
$output = '<img src="'.$matches [1] [0].'" alt="">';
}
return $output;
}

لینک به ارسال

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

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

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

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

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

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

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

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

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