WordPress the page call category

  1. Copy index.php in theme files, rename the file such as : blogs.php

  2. Open this file, and input below to the file top:

    <?php

    /*

    Template Name: Blogs

    */

    ?>

  3. Search <?phpif(have_posts()):?> , and input before<?phpquery_posts(‘showposts=15&cat=1’);?> , you can modify “cat=1″ to which category you want.

  4. Creat a page such as “blogs”, and the template select “Blogs” and then you can publish it.

    有时候需要调用wp 某个分类下的文章

    只要把这个代码放在你的WordPress任意页面的任意位置都能显示指定调用的文章类别,并且还可以控制文章输出的条数。

    ====================================
    <?php $posts = get_posts( “category=4&numberposts=10″ ); ?>
    <?php if( $posts ) : ?>
    <ul><?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
    <li>
    <a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title(); ?>”><?php the_title(); ?></a>
    </li>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>
    ====================================
    category=4&numberposts=10是控制需要调用的大类的ID和输出文章条数就ok

    WP调用单个分类文章列表技巧

    ====================================
    <h2><?php wp_list_categories(‘include=11&title_li=&style=none’); ?></h2> //输出 ID 为11的分类的标题

    <?php echo category_description(11); ?> //输出 ID 为11的分类的描述

    <?php query_posts(‘showposts=5&=11’); ?> //query_posts 给 The Loop 限定的条件是:显示5篇日志和分类 ID 为11

    <?php while (have_posts()) : the_post(); ?> //The Loop 开始

    <li><a href=”<?php the_permalink() ?>” rel=”bookmark” class=”title”><?php the_title(); ?></a></li> //用列表的方式输出带有链接的文章标题

    <?php endwhile; ?> //The Loop 结束
    ====================================

    解决 WordPress 页面调用分类文章后无法翻页的问题

    有网友反映说使用上面的方法造成无法翻页的状况,症状为 WordPress 页面调用分类文章后,点击页面下方的翻页没有反应,但浏览器地址栏传递的参数已经发生改变了。出现此问题可参考下面的解决方法:

    将上面提到过的代码:

    <?php query_posts('showposts=5&=11'); ?>

    替换为:

    1
    2
    3
    4
    5
    6
    <?php
    $limit = get_option('posts_per_page');
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('=1&showposts=' . $limit=15 . '&paged=' . $paged);
    $wp_query->is_archive = true; $wp_query->is_home = false;
    ?>
    在介绍一个插件WP Page Numbers结合来用是比较不错的,其中插件页面有使用的方法,在哪使用要调用一句<?php if(function_exists(‘wp_page_numbers’)) : wp_page_numbers(); endif; ?>
    20140629更新

    WordPress调用当前栏目下的post内容


    <?php
    //if ( is_single() ) :
    global $post;
    $categories = get_the_category();
    foreach ($categories as $category) :
    ?>
    <li class="pagenav">
    <h3 class="widgettitle"><?php echo $category->name; ?></h3>
    <ul>
    <?php
    $posts = get_posts('numberposts=5&category='. $category->term_id);
    foreach($posts as $post) :
    ?>
    <li class="page_item"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>
    </li>
    <?php
    endforeach;
    //endif ;
    ?>

    page文章页面父子页面调用


    <?php
    $output = wp_list_pages('echo=0&depth=1&title_li=<h3 class="widgettitle">列表</h3>' );
    if (is_page( )) {
    $page = $post->ID;
    if ($post->post_parent) {
    $page = $post->post_parent;
    }
    $children=wp_list_pages( 'echo=0&child_of=' . $page . '&title_li=' );
    if ($children) {
    $output = wp_list_pages ('echo=0&child_of=' . $page . '&title_li=<h3 class="widgettitle">Calf.one</h3>');
    }
    }
    echo $output;
    ?>

Readers Comments (4)

  1. I am genuinely thankful to the owner of this web site who has shared this great article
    at at this time.

    Reply
  2. I used to be recommended this blog via my cousin. I’m now not sure whether this publish is
    written via him as nobody else recognize such particular about my difficulty.
    You are amazing! Thanks!

    Reply
  3. Fantastic site you have here but I was curious if you knew of
    any user discussion forums that cover the same topics discussed in this article?
    I’d really love to be a part of online community where
    I can get suggestions from other experienced individuals that share the same interest.

    If you have any recommendations, please let me know. Bless you!

    Reply
  4. Do you have a spam problem on this blog; I also am a blogger, and I was wondering your situation; we have created some nice practices and we are looking to trade strategies
    with other folks, why not shoot me an email if interested.

    Reply

Leave a comment

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.

calf-blog-top