***รบกวนผู้รู้นิดนึงครับ ใครพอทราบโค้ด php มันไป get มาจากไฟล์ไหน

เริ่มโดย hastyman, 04 พฤศจิกายน 2012, 00:11:03

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

hastyman

ใครพอทราบโค้ด php ข้างล่างมันไป get มาจากไฟล์ไหน
โค้ดจาก theme ไฟล์ index.php
...
   <div class="story">
   <?php if ( !get_option('bmg_thumbnail')) {?>
   <?php get_thumbnail($post->ID); ?>   
   <?php } ?>
   <?php the_excerpt();?>
   </div>
...

คือผมต้องการแก้หน้า homepage ที่มันตัดคำแต่ละ post ให้มีคำว่า read more
แทน [...] และใส่ลิงค์เข้าไปด้วยครับ

รบกวนผู้รู้นิดนึงครับ


:wanwan004:

ball6847

We use Ubuntu.

[direct=http://ng-seo.sourcelab.xyz/]AngularJS SEO Experimental[/direct]

Shiseido

[direct=https://www.ตับแข็ง.com]ตับแข็ง[/direct] [direct=https://green-curmin.com/]green curmin[/direct][direct=https://shop.line.me/@arshithong]arshithong gold[/direct] [direct=https://shop.line.me/@macunox]macunox มาคูน็อกซ์[/direct]
[direct=https://shop.line.me/@greencurmin]กรีนเคอมิน[/direct]

hastyman

อ้างถึงจาก: ball6847 ใน 04 พฤศจิกายน 2012, 00:19:26
http://codex.wordpress.org/Function_Reference/the_excerpt#Make_the_.22read_more.22_link_to_the_post

ล่างๆครับ ลองทำตามดู เขียนไว้ใน functions.php ของ theme ครับ

ใส่ไว้ Line ไหนครับ ดำน้ำแย่แล้ว

function new_excerpt_more($more) {
      global $post;
   return ' <a href="'. get_permalink($post->ID) . '">Read the Rest...</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

---------------

โค้ดจาก wp-includes 3.1.3 ไฟล์ post-template.php
/**
* Display the post excerpt.
* @since 0.71
* @uses apply_filters() Calls 'the_excerpt' hook on post excerpt.
*/

function the_excerpt() {
   echo apply_filters('the_excerpt', get_the_excerpt());
}

/**
* Retrieve the post excerpt.
* @since 0.71
* @param mixed $deprecated Not used.
* @return string
*/

function get_the_excerpt( $deprecated = '' ) {
   if ( !empty( $deprecated ) )
      _deprecated_argument( __FUNCTION__, '2.3' );

   global $post;
   $output = $post->post_excerpt;
   if ( post_password_required($post) ) {
      $output = __('There is no excerpt because this is a protected post.');
      return $output;
   }

   return apply_filters('get_the_excerpt', $output);
}

---------------------

โค้ดจาก theme ไฟล์ functions.php
function theme_add_admin() {

global $themename, $shortname, $options;  

if ( $_GET['page'] == basename(__FILE__) ) {
   if ( 'bmg_update' == $_REQUEST['action'] ) {
      
      update_option('bmg_featured', $_REQUEST['bmg_featured']);
      update_option('bmg_featured_count', $_REQUEST['bmg_featured_count']);
      update_option('bmg_med_featured', $_REQUEST['bmg_med_featured']);
      update_option('bmg_tab_sb', $_REQUEST['bmg_tab_sb']);
      update_option('bmg_middle_sb', $_REQUEST['bmg_middle_sb']);
      update_option('bmg_bottom_sb', $_REQUEST['bmg_bottom_sb']);
      update_option('bmg_footer', $_REQUEST['bmg_footer']);
      update_option('bmg_thumbnail', $_REQUEST['bmg_thumbnail']);   
      
   }
   
}

   add_theme_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'theme_admin');
}
*

------------------

โค้ดจาก theme ไฟล์ index.php

   <div class="story">
   <?php if ( !get_option('bmg_thumbnail')) {?>
   <?php get_thumbnail($post->ID); ?>   
   <?php } ?>
   <?php the_excerpt();?>
   </div>
   <div class="tags"><small><?php the_tags( 'Tags: [', ', ', ']'); ?></small></div>   
   </div>

ball6847

ไฟล์ functions.php จะอยู่ในโฟลเดอร์ของ theme ครับ อยู่ที่เดียวกับไฟล์ index.php ของ theme นั่นแหละครับ เอาไว้ตรงไหนของไฟล์ก็ได้ แทรกไปด้านล่างก็ได้ ส่วนไฟล์ index.php ไม่ต้องไปแก้อะไรครับ
We use Ubuntu.

[direct=http://ng-seo.sourcelab.xyz/]AngularJS SEO Experimental[/direct]

rukrean

   <div class="story">
   <?php if ( !get_option('bmg_thumbnail')) {?>
   <?php get_thumbnail($post->ID); ?>   
   <?php } ?>
   <?php the_excerpt();?>
 
<div class="more"><a href="<?php the_permalink(); ?>">Read More..</a></div>

   </div>

เขียนแบบนี้ก็ได้ครับ แต่เวลาก่อนโพสต์บทความให้เราทำการตัดบทความก่อนนะครับ แต่ถ้าต้องการให้มันตัดบทความแบบ auto ก็เข้าไปแก้ใน functions.php ดังที่กล่าวไว้ในข้างต้นได้ครับ

# Skill : HTML, CSS, Blogger, Wordpress, SEO, Writer #

- [direct=https://bunditchon.com]บัณฑิตชน – ข้อสอบพร้อมเฉลยฟรี[/direct]
- [direct=https://thaisimplesoft.blogspot.com/]ThaiSimpleSoft – พัฒนาโปรแกรมแจกฟรี[/direct]

hastyman

ผมลองใส่ไว้ในไฟล์ fucntion แล้ว

แต่ theme มันเก่า อาจไม่แมตกับ Wordpress 3.1.3

ขอบคุณทั้ง 3 ท่านครับ



:wanwan017: :wanwan017: :wanwan017: