0

I have this webpage with blog and a page with latest news. Right now both pages are showing the same category. How do I separate them? so that one page show category 1 and the other show category 2?

code for category_blog.php

<!--<tm_category>-->

<!--<div if else tm_category>-->
<?php if ( is_active_sidebar( 'category-sidebar-widget-left' ) && is_active_sidebar( 'category-sidebar-widget-right' ) ) { ?>
<div class="tm_category_2">

<?php } elseif ( is_active_sidebar( 'category-sidebar-widget-left' ) ) { ?>
<div class="tm_category_1">

<?php } elseif ( is_active_sidebar( 'category-sidebar-widget-right' ) ) { ?>
<div class="tm_category_1_right">

<?php } else { ?>
<div class="tm_category_0">

<?php } ?>
<!--</div if else tm middle post>-->

    <!--<category name>-->
    <div class="tm_cat_metatitle">
        <h1>
            <i class="icon-reorder"></i> 
            <?php echo single_cat_title( '', false ); ?> 
        </h1> 
        <div class="tm_cat_arrow"></div>
    </div>
    <!--</category name>-->

    <!--<tm_category_file>-->
    <div class="tm_category_file">
        <div class="tm_category_box">

        <?php if ( have_posts() ) : ?>

            <!--<the loop>-->
            <?php while ( have_posts() ) : the_post(); ?>
            <div <?php post_class(); ?>>

                <!--<cat title>-->
                <div class="tm_catpost_titles">
                        <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">
                            <h1 class="tmpost-<?php the_ID(); ?>">
                            <?php $tit = the_title('','',FALSE); echo substr($tit, 0, 150); if (strlen($tit) > 150) echo " ..."; ?>
                            </h1>
                        </a>
                </div>
                <!--</cat title>-->     

                <!--<cat item>-->
                <div class="tm_cat_item">
                    <div class="tmpost-<?php the_ID(); ?>-item">

                        <div class="tm_catpost_item_1">
                        <i class="icon-user"></i> 
                        <?php _e('By', 'tm_myid_text'); ?> <?php the_author(); ?>
                        </div>

                        <div class="tm_catpost_item_2">
                        <i class="icon-tag"></i> 
                        <?php _e('In', 'tm_myid_text'); ?> <?php $category = get_the_category(); echo $category[0]->cat_name; ?>
                        </div>

                        <div class="tm_catpost_item_3">
                        <i class="icon-calendar"></i>
                        <?php the_time('M jS, Y') ?>
                        </div>

                        <div class="tm_catpost_item_4">
                        <i class="icon-comments"></i> 
                        <?php comments_number(__('0 Comments', 'tm_myid_text'), __('1 Comment', 'tm_myid_text'), __( '% Comments', 'tm_myid_text') );?>
                        </div>

                        <div class="tm_catpost_item_5">
                        <i class="icon-eye-open"></i> 
                        <?php echo tm_viewcounter_display(get_the_ID()); ?>
                        </div>

                    </div>
                </div>
                <!--</cat item>-->

                <!--<cat image>-->
                <div class="tm_cat_image">
                <?php if (has_post_thumbnail()) { ?>
                    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                    <?php the_post_thumbnail( 'full' ); ?>
                    </a>
                <?php } else { ?>
                <?php } ?>
                </div>
                <!--</cat image>-->

                <div class="tm_cat_desc">
                    <div class="tmpost-desc">
                    <?php echo excerpt(300); ?> 
                    </div>

                    <div class="tm_cat_readmore">
                        <div class="tmpost-readmore">
                            <a href="<?php the_permalink() ?>">
                                <i class="icon-file-text"></i> 
                                <?php _e('Read More', 'tm_myid_text'); ?>
                            </a>
                            <div class="tmpost-readmore_list"></div>
                        </div>
                    </div>

                </div>

            </div>
            <?php endwhile; ?>
            <!--</the loop>-->

        </div>
    </div>
    <!--</tm_category_file>-->

    <!--<tm pagination>-->
    <div id="Nav">
        <div class="tm_navigation">
        <?php echo tm_pagination_nav(); ?>
        </div>
    </div>
    <!--</tm pagination>-->

        <?php else : ?>
        <?php endif; ?>

</div>
<!--</tm_category>-->

this is the index code:

<?php 
/* Template Name: Home 5 */
?>

<?php get_header(); ?>

<!--<home 5>-->

<!--<div tm_category 0>-->
<div class="tm_category_0">
<!--</div tm_middle 0>-->

    <!--<category name>-->
    <div class="tm_cat_metatitle">
        <h1>
            <i class="icon-reorder"></i> 
             Recent Posts           
        </h1> 
        <div class="tm_cat_arrow"></div>
    </div>
    <!--</category name>-->

    <!--<tm_category_file>-->
    <div class="tm_category_file">
        <div class="tm_category_box_home5">

        <?php if ( have_posts() ) : ?>

            <!--<the loop>-->
            <?php $wp_query = new WP_Query( array( 
                                                "cat" => "", 
                                                "posts_per_page" => "", 
                                                "post_type" => "post",
                                                "paged" => get_query_var('paged') ? get_query_var('paged') : 1
                                                )                                               
                                        );
            while( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

            <div <?php post_class(); ?>>

                <!--<cat title>-->
                <div class="tm_catpost_titles">
                        <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">
                            <h1 class="tmpost-<?php the_ID(); ?>">
                            <?php $tit = the_title('','',FALSE); echo substr($tit, 0, 150); if (strlen($tit) > 150) echo " ..."; ?>
                            </h1>
                        </a>
                </div>
                <!--</cat title>-->     

                <!--<cat item>-->
                <div class="tm_cat_item">
                    <div class="tmpost-<?php the_ID(); ?>-item">

                        <div class="tm_catpost_item_1">
                        <i class="icon-user"></i> 
                        <?php _e('By', 'tm_myid_text'); ?> <?php the_author(); ?>
                        </div>

                        <div class="tm_catpost_item_2">
                        <i class="icon-tag"></i> 
                        In <?php $category = get_the_category(); echo $category[0]->cat_name; ?>
                        </div>

                        <div class="tm_catpost_item_3">
                        <i class="icon-calendar"></i>
                        <?php the_time('M jS, Y') ?>
                        </div>

                        <div class="tm_catpost_item_4">
                        <i class="icon-comments"></i> 
                        <?php comments_number(__('0 Comments', 'tm_myid_text'), __('1 Comment', 'tm_myid_text'), __( '% Comments', 'tm_myid_text') );?>
                        </div>

                        <div class="tm_catpost_item_5">
                        <i class="icon-eye-open"></i> 
                        /*<?php echo tm_viewcounter_display(get_the_ID()); ?>/*
                        </div>

                    </div>
                </div>
                <!--</cat item>-->

                <!--<cat image>-->
                <div class="tm_cat_image">
                <?php if (has_post_thumbnail()) { ?>
                    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                    <?php the_post_thumbnail( 'Full' ); ?>
                    </a>
                <?php } else { ?>
                <?php } ?>
                </div>
                <!--</cat image>-->

                <div class="tm_cat_desc_home5">
                    <div class="tmpost-desc">
                    <?php the_content(); ?>
                    </div>

                    <div class="tm_cat_readmore">

                        <div class="tmpost-readmore">
                            <a href="<?php the_permalink() ?>">
                                <i class="icon-file-text"></i> 
                                 <?php comments_number(__('(0) Kommentarer ', 'tm_myid_text'), __('(1) Kommentar', 'tm_myid_text'), __( '(%) Kommentarer', 'tm_myid_text') );?> 
                            </a>
                            <div class="tmpost-readmore_list"></div>
                        </div>
                    </div>

                </div>

            </div>

            <?php endwhile; ?>
            <!--</the loop>-->

        </div>
    </div>
    <!--</tm_category_file>-->

    <!--<tm pagination>-->
    <div id="Nav">
        <div class="tm_navigation">
        <?php echo tm_pagination_nav(); ?>
        </div>
    </div>
    <!--</tm pagination>-->

        <?php else : ?>
        <?php endif; ?>

</div>

<!--</home left>-->
<?php get_template_part( 'sidebar_left' ); ?>
<!--</home left>-->
<!--</home 5>-->

<?php get_footer(); ?>
16
  • Paste your code
    – user48752
    Commented Apr 10, 2014 at 12:04
  • from witch page? You want to see my index file or category.php or category_blog.php?
    – bear
    Commented Apr 10, 2014 at 12:28
  • Which page do you want to show post of different categories?
    – user48752
    Commented Apr 10, 2014 at 12:32
  • Can you paste the code for blog page?
    – user48752
    Commented Apr 10, 2014 at 12:40
  • 1
    "its in the question, was to long for comment" You should always edit your question if you need to add code +1 Commented Apr 10, 2014 at 12:57

1 Answer 1

0

Change the cat to the category number you want. For example:

 "cat" => 2, 

Or if you know the category name you could also use:

"category" =>"category_name", 

You should add any of the above two lines in your wp_query arguments like the one in below which is empty:

$wp_query = new WP_Query( array( 
                                                    "cat" => "", 
                                                    "posts_per_page" => "", 
                                                    "post_type" => "post",
                                                    "paged" => get_query_var('paged') ? get_query_var('paged') : 1
                                                    )                                               
                                            );
10
  • but if I change that wont both pages show the same category then?
    – bear
    Commented Apr 10, 2014 at 12:55
  • Change the Wp_Query of one of the page and it will show post of different category. For example change the cat for your SENASTE NUMMRET page and that page will show post of different category
    – user48752
    Commented Apr 10, 2014 at 13:00
  • I dont undertand. Bot pages are using the same index. How do I change on just one page?
    – bear
    Commented Apr 10, 2014 at 13:03
  • Do you have access to code for SENASTE NUMMRET page?
    – user48752
    Commented Apr 10, 2014 at 13:05
  • SENASTE NUMMRET is using the same code as the other page BLOG. both pages are using the same code and index
    – bear
    Commented Apr 10, 2014 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.