最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - Displaying different posts Via wp_list_categories()

programmeradmin0浏览0评论

I believe this problem to be quite simple but can't seem to get my head around how to solve it.

So I'm pulling in all the category with posts in using wp_list_categories();

My problem is when I click through it pulls in the correct posts but, I want it to pull in the correct posts and still have wp_list_categories links at the top so someone can switch between the posts.

So really all that needs to change is that when you click a category link the relevant posts get pulled looking the same as there displayed now.

I know this is going to involve conditions and maybe some new queries written - I want to try and do this in the most robust way possible.

Link to the page

code at the moment generating this page.

<?php
/*
 *  * Template Name: Case Studies
 */
?>
<?php global $up_options, $post, $paged, $wp_query; ?>
<?php get_header(); ?>
<div id="bodywrapper">
        <?php $args = array(
            'title_li'           => __( '' ),
        ); ?>
        <div class="category-list"><?php wp_list_categories($args); ?></div>
    <div style="height: 25px"></div>

    <div id="content"> 
        <h1>Case Studies</h1>

     <?php
    $start = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query();
      $wp_query->query('posts_per_page=5&post_type=post'.'&paged='.$paged);
        while ($wp_query->have_posts()) : $wp_query->the_post(); 
                    ?>
                    <div id="post-<?php the_ID(); ?>" class="post">
                        <a href="<?php the_permalink() ?>">
                            <?php if (has_post_thumbnail()) { ?>
                                <?php the_post_thumbnail('thumbnail'); ?>
                            <?php }?>
                        </a>
                        <h1 class="post-title"><a href="<?php  echo get_post_meta($post->ID, 'lj_file_url', true) ?>" title="<?php the_title(); ?>"> <?php the_title(); ?></a></h1>
                        <div class="post-entry">
<a href="<?php  echo get_post_meta($post->ID, 'lj_file_url', true) ?>" title="Download pdf <?php the_title(); ?>"> <img src=".png" alt="" class="alignleft"/></a>
                            <?php the_excerpt(); ?>
                        </div>
                    </div>
                <?php endwhile; ?>
                <div class="clear">
                    <?php wpld_pagenavi(); ?>
                </div>

<br/><br/><br/><br/><br/><br/>

<p style="text-align: center;"><span style="font-size: 35px;"><span style="color: #2788e4;">Secure Solutions</span></span></p>
    </div>
    <?php get_footer(); ?>

I believe this problem to be quite simple but can't seem to get my head around how to solve it.

So I'm pulling in all the category with posts in using wp_list_categories();

My problem is when I click through it pulls in the correct posts but, I want it to pull in the correct posts and still have wp_list_categories links at the top so someone can switch between the posts.

So really all that needs to change is that when you click a category link the relevant posts get pulled looking the same as there displayed now.

I know this is going to involve conditions and maybe some new queries written - I want to try and do this in the most robust way possible.

Link to the page

code at the moment generating this page.

<?php
/*
 *  * Template Name: Case Studies
 */
?>
<?php global $up_options, $post, $paged, $wp_query; ?>
<?php get_header(); ?>
<div id="bodywrapper">
        <?php $args = array(
            'title_li'           => __( '' ),
        ); ?>
        <div class="category-list"><?php wp_list_categories($args); ?></div>
    <div style="height: 25px"></div>

    <div id="content"> 
        <h1>Case Studies</h1>

     <?php
    $start = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query();
      $wp_query->query('posts_per_page=5&post_type=post'.'&paged='.$paged);
        while ($wp_query->have_posts()) : $wp_query->the_post(); 
                    ?>
                    <div id="post-<?php the_ID(); ?>" class="post">
                        <a href="<?php the_permalink() ?>">
                            <?php if (has_post_thumbnail()) { ?>
                                <?php the_post_thumbnail('thumbnail'); ?>
                            <?php }?>
                        </a>
                        <h1 class="post-title"><a href="<?php  echo get_post_meta($post->ID, 'lj_file_url', true) ?>" title="<?php the_title(); ?>"> <?php the_title(); ?></a></h1>
                        <div class="post-entry">
<a href="<?php  echo get_post_meta($post->ID, 'lj_file_url', true) ?>" title="Download pdf <?php the_title(); ?>"> <img src="http://www.integra-av.co.uk/wp-content/uploads/2012/04/pdflogo.png" alt="" class="alignleft"/></a>
                            <?php the_excerpt(); ?>
                        </div>
                    </div>
                <?php endwhile; ?>
                <div class="clear">
                    <?php wpld_pagenavi(); ?>
                </div>

<br/><br/><br/><br/><br/><br/>

<p style="text-align: center;"><span style="font-size: 35px;"><span style="color: #2788e4;">Secure Solutions</span></span></p>
    </div>
    <?php get_footer(); ?>
Share Improve this question asked Oct 15, 2013 at 16:14 dannyw24dannyw24 4511 gold badge6 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Refer to the Template Hierarchy. You'll need to create a category.php template file, since the category archive index is what gets displayed when clicking a category link in the wp_list_categories() output.

发布评论

评论列表(0)

  1. 暂无评论