1

私は「WordPress」で本当に新しく、現在FUNDAテーマを使用しており、カテゴリIDに応じて3つの異なる列に投稿の3つの異なるカテゴリを表示しようとしていますが、特定のカテゴリの投稿を見つけることができないという問題に直面しています。

私はこれを試します

<?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

そのコードは 1 つのカテゴリのみを示しています。if ステートメントの代わりに、カテゴリ ID の配列を追加し、for ループを使用してコードを乗算する必要があります。多分そのようなもの。

次に、コンテンツを異なるボックスに分割する CSS を少し作成しますか? 3列の意味がわかりません。また、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 に答える