ThaiSEOBoard.com

พัฒนาเว็บไซต์ => CMS & Free Script => ข้อความที่เริ่มโดย: T l2 0 J A N ที่ 16 เมษายน 2010, 14:34:06



หัวข้อ: ทำยังไงให้หน้าแรกของ WP แสดง Post ใน Categories ที่ต้องการ
เริ่มหัวข้อโดย: T l2 0 J A N ที่ 16 เมษายน 2010, 14:34:06
ลองแก้ตามนี้แล้วไม่ได้ วิธีจาก http://wordpress.org/support/topic/263596



ORIGINAL index.php
โค๊ด:
<?php get_header(); ?>

<div id="content">
  <?php if (have_posts()) : ?>
  <?php while (have_posts()) : the_post(); ?>

NEW index.php
โค๊ด:
<?php get_header(); ?>

<div id="content">
  <?php query_posts(&#39;showposts=20&amp;cat=3&#39;); ?>
  <?php if (have_posts()) : ?>
  <?php while (have_posts()) : the_post(); ?>


หัวข้อ: Re: ทำยังไงให้หน้าแรกของ WP แสดง Post ใน Categories ที่ต้องการ
เริ่มหัวข้อโดย: Nomkhonwaan ที่ 16 เมษายน 2010, 23:12:51
หมายถึงแสดง Post จาก Category ที่ต้องการเนาะ งั้นตามนี้ เลยครับ

โค๊ด:
query_posts(array(
'posts_per_page' => 1, /* จำนวน post ที่ต้องการแสดง ถ้าอยากห้ออกมา 10 ก็ใส่ 10*/
'cat' => 1 /* Category ID ดูได้จากหน้า Category ตรง Dashboard กดแล้วสังเกตุที่ link มันจะมีบอกครับ */
));

while( have_posts() ) : the_post(); /* เรียก posts ที่ query ได้ออกมาจนกว่าจะหมด */

/* ข้อมูล posts ที่จะ เรียกออกมาคร่าวๆ ก็มี */
the_content(); /* แสดงเนื้อหาของ posts */
the_title(); /* แสดง title */
the_author(); /* แสดงผู้เขียน */
the_time('d - m - Y'); /* ฟังก์ชันนี้ข้างในเป็น date/time string format ดูตัวอย่างได้จาก wordpress */

endwhile;

คร่าวๆ ตามนี้ครับ ที่เหลือลองปรับแต่งดูเองน่ะครับ  :wanwan023:

เพิ่มเติม http://codex.wordpress.org/Function_Reference/query_posts