ThaiSEOBoard.com

พัฒนาเว็บไซต์ => Programming => ข้อความที่เริ่มโดย: konchan ที่ 09 พฤษภาคม 2011, 14:08:42



หัวข้อ: หน้า Home wordpress แบบเลือกโพสได้ สอบถามปัญหา Php
เริ่มหัวข้อโดย: konchan ที่ 09 พฤษภาคม 2011, 14:08:42
พี่ๆครับ รบกวนดูโค้ดหน้าแรกให้ผมหน่อยครับ พอดีผมสร้างหน้าโฮมเพจ แบบ เลือกโพสได้ว่าจะเอาโพสไหนอยู่ อันดับ 1 2 3 ในหน้าแรก แต่ทีนี้ โค้ดมันยาวไปหน่อยอ่ะครับ ใช้ฟังก์ชั่นใช้งานก็ ซ้ำๆ กัน เรยอยากจะถามว่า มันมีวิธีที่ทำให้ ฟังก์ชั่นทำงาน ไม่ซ้ำกันไม๊ครับ  อันนี้เป็นของ wordpress ครับ อันที่ซ้ำกันคือ
$postid=array( $moso_options ['postid1'] );
อันนี้อ่ะครับ รับค่าจาก postid1,postid2,postid3 รบกวนพี่ๆช่วยผมหน่อยน๊ะครับ ^^ :wanwan017: :wanwan017:


โค๊ด:
<?php global $moso_options?>
<?php get_header(); ?>
<?php if (have_posts()) : ?>
<?php 
$postid
=array( $moso_options ['postid1'] ); //post id = 7
// The Query
$my_query = new WP_Query( array( 'post__in' =>$postid ) );
while (
$my_query->have_posts()) : $my_query->the_post(); 
$do_not_duplicate $post->ID?>

<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php 
$postid
=array( $moso_options ['postid2'] );//post id = 54
// The Query
$my_query = new WP_Query( array( 'post__in' =>$postid ) );
while (
$my_query->have_posts()) : $my_query->the_post(); 
$do_not_duplicate $post->ID?>

<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php 
$postid
=array( $moso_options ['postid3'] ); //post id = 4
// The Query
$my_query = new WP_Query( array( 'post__in' =>$postid ) );
while (
$my_query->have_posts()) : $my_query->the_post(); 
$do_not_duplicate $post->ID?>

<?php the_excerpt(); ?>
<?php endwhile; ?>

<?php 
$postid
=array( $moso_options ['postid4'] ); //post id = 10
// The Query
$my_query = new WP_Query( array( 'post__in' =>$postid ) );
while (
$my_query->have_posts()) : $my_query->the_post(); 
$do_not_duplicate $post->ID?>

<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php 
$postid
=array( $moso_options ['postid5'] ); //post id = 108
// The Query
$my_query = new WP_Query( array( 'post__in' =>$postid ) );
while (
$my_query->have_posts()) : $my_query->the_post(); 
$do_not_duplicate $post->ID?>

<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php get_sidebar(); ?>      
<?php get_footer(); ?>




หัวข้อ: Re: หน้า Home wordpress แบบเลือกโพสได้ สอบถามปัญหา Php
เริ่มหัวข้อโดย: konchan ที่ 10 พฤษภาคม 2011, 13:57:34
ดันหน่อยครับบ มีพี่ๆคนไหนเก่ง รบกวนชี้แนะด้วยน๊ะครับ


หัวข้อ: Re: หน้า Home wordpress แบบเลือกโพสได้ สอบถามปัญหา Php
เริ่มหัวข้อโดย: konchan ที่ 13 พฤษภาคม 2011, 13:25:25
อีกซักรอบครับ ถ้าไม่มีคนตอบคงต้องหาวิธีใหม่แล้วคับ แฮะๆๆๆ


หัวข้อ: Re: หน้า Home wordpress แบบเลือกโพสได้ สอบถามปัญหา Php
เริ่มหัวข้อโดย: shokarita ที่ 13 พฤษภาคม 2011, 16:18:15
โค๊ด:
<?php
global $moso_options;
get_header();
if (have_posts())
$totalOption  count($moso_options);
for($i=1;$i<=$totalOption;$i++){
$postid=array( $moso_options ['postid'.$i] ); //post id = 7
$my_query = new WP_Query( array( 'post__in' =>$postid ) );
while ($my_query->have_posts()) { 
$my_query->the_post();
$do_not_duplicate $post->ID;  
the_excerpt(); 
}
}

get_sidebar();
get_footer();

?>
น่าจะสั้นพอนะครับ