1

我是“WordPress”的新手,目前面临的问题是我正在使用 FUNDA 主题并尝试根据类别 ID 在三个不同的列中显示三个不同类别的帖子,但找不到特定类别的帖子。

我试试这个

<?php 
    $data = cats_to_select(); 
    $cat_id = $data[1][value];
    global $cat_id;?>
    <?php print_r($cat_id);?>

<?php if($cat_id==3):?>
    <?php if (have_posts()) : ?>    
    <?php while (have_posts()) : the_post(); ?>
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
                                        <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) { the_post_thumbnail(array(260,200), array("class" => "alignleft post_thumbnail")); } ?>
                                        <h2 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                                        <div class="postdate"><img src="<?php bloginfo('template_url'); ?>/images/date.png" /> <?php the_time('F jS, Y') ?> <img src="<?php bloginfo('template_url'); ?>/images/user.png" /> <?php the_author() ?> <?php if (current_user_can('edit_post', $post->ID)) { ?> <img src="<?php bloginfo('template_url'); ?>/images/edit.png" /> <?php edit_post_link('Edit', '', ''); } ?></div>

                                <div class="entry">
                                    <?php the_content('<strong>Read more &raquo;</strong>'); ?>
                                </div>
                                    </div><!--/post-<?php the_ID(); ?>-->

<?php endwhile; ?>
<div class="navigation">
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
<?php } ?>
</div>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
                                <?php get_search_form(); ?>
<?php endif; ?>
<?php endif; ?>

谁能帮我?提前致谢。

4

2 回答 2

1

该代码仅显示一个类别。您需要添加一个类别 ID 的数组,并可能使用 for 循环来乘以代码,而不是 if 语句。也许是这样的。

然后制作一些将内容分成不同盒子的css?我不确定您所说的三列是什么意思。也不知道 FUNDA 的主题是什么。

如果您可以让我们更好地了解您正在使用什么,那就更容易了。关联?

于 2012-09-25T23:03:28.123 回答
1
<?php query_posts('cat=3'); ?> // here, 3 will be replaced with desired
                             // category id, or you may add array 
<?php if (have_posts()) : ?>    
    <?php while (have_posts()) : the_post(); ?>
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
                                        <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) { the_post_thumbnail(array(260,200), array("class" => "alignleft post_thumbnail")); } ?>
                                        <h2 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                                        <div class="postdate"><img src="<?php bloginfo('template_url'); ?>/images/date.png" /> <?php the_time('F jS, Y') ?> <img src="<?php bloginfo('template_url'); ?>/images/user.png" /> <?php the_author() ?> <?php if (current_user_can('edit_post', $post->ID)) { ?> <img src="<?php bloginfo('template_url'); ?>/images/edit.png" /> <?php edit_post_link('Edit', '', ''); } ?></div>

                                <div class="entry">
                                    <?php the_content('<strong>Read more &raquo;</strong>'); ?>
                                </div>
                                    </div><!--/post-<?php the_ID(); ?>-->

<?php endwhile; ?>
于 2012-09-26T09:31:58.983 回答