回首頁 網路知識wordpress 熱門文章、相關文章、最新發表等語法
2009
05/13

wordpress 熱門文章、相關文章、最新發表等語法

瀏覽:2,013人次
作者:英創達

相關文章

<ul>
<?php
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$first_tag = $tags[0]->term_id;
$args=array(
‘tag__in’ => array($first_tag),
‘post__not_in’ => array($post->ID),
‘showposts’=>10,
‘caller_get_posts’=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?> <?php comments_number(‘ ‘,’(1)’,'(%)’); ?></a> </li>
<?php
endwhile;
}
}
?>
</ul>

隨機文章

<?php
query_posts(array(‘orderby’ => ‘rand’, ‘showposts’ => 2));
if (have_posts()) :
while (have_posts()) : the_post();?>
<a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?></a>&nbsp;<?php comments_number(”, ‘(1)’, ‘(%)’); ?><br />
<?php endwhile;endif; ?>

最新迴響

 <?php
global $wpdb;
$sql = “SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,30) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)WHERE comment_approved = ’1′
AND comment_type = post_password  ORDER BY comment_date_gmt DESC LIMIT 10″;
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
foreach ($comments as $comment) {
$output .= “n<li>”. “<a href=”" . get_permalink($comment->ID).”#comment-” . $comment->comment_ID . “” title=”on “.$comment->post_title . “”>”.strip_tags($comment->comment_author).”</a>” .”: ” .strip_tags($comment->com_excerpt).”</li>”;
}
$output .= $post_HTML;
echo $output;
?>

最新文張

<?php get_archives(“postbypost”, “6″, “html”, ” “, ” “); ?>
VN:F [1.9.6_1107]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.6_1107]
Rating: 0 (from 0 votes)

總共有2 篇發表於 “wordpress 熱門文章、相關文章、最新發表等語法”

  1. 365网购吧 說道:

    你好,相关文章调不出来是怎么回事?谢谢

    VA:F [1.9.6_1107]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.6_1107]
    Rating: 0 (from 0 votes)
  2. Tony 說道:

    這個語法用了之後
    還會跑出文章內容出來
    無法做出列表?

    VA:F [1.9.6_1107]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.6_1107]
    Rating: 0 (from 0 votes)

留下您的意見

(若看不到驗證碼,請重新整理網頁。)