Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

hope things are going well.

I'm trying to create a member's only section specific for posts of about job opportunities. My goal is to have posts of this category displayed on this page and excluded from the index.php page. I have created a template page by altering archive.php. The category ID for this "employment opportunities" category is 9. I have used the following php code to succesfully only display posts from that category on the template page and exclude posts of this category from index.php:

<?php query_posts('cat=9'); ?>

My issues are these.

  1. This template page is not keeping the same template formatting as index.php and archive.php, even though I have not changed the CSS in any way. The code for index.php, archive.php, and empopp-template.php are below.

index.php

<?php
/**
* Index Template
*
* This is the default template.  It is used when a more specific template can't be      found to display
* posts.  It is unlikely that this template will ever be used, but there may be rare    cases.
*
* 
* 
*/

get_header(); // Loads the header.php template. ?>

<div class="aside">

    <?php get_template_part( 'menu', 'secondary' ); // Loads the menu-     secondary.php template.  ?>

    <?php get_sidebar( 'primary' ); // Loads the sidebar-primary.php template.   ?>

</div>

<?php do_atomic( 'before_content' ); // oxygen_before_content ?>

<div class="content-wrap">

    <div id="content">

        <?php do_atomic( 'open_content' ); // oxygen_open_content ?>

        <div class="hfeed">

            <?php query_posts('cat=-9'); ?>

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

                <?php while ( have_posts() ) : the_post(); ?>

                    <?php do_atomic( 'before_entry' ); // oxygen_before_entry ?>

                        <div id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">       

                        <?php do_atomic( 'open_entry' ); // oxygen_open_entry ?>



                        <div class="entry-header">

                            <?php echo apply_atomic_shortcode( 'entry_title', '[entry-title]' ); ?>

                            <?php echo apply_atomic_shortcode( 'byline', '<div class="byline">' . __( '[entry-published] &middot; by [entry-author] &middot; in [entry-terms taxonomy="category" before=""] [entry-edit-link before=" &middot; "]', 'oxygen' ) . '</div>' ); ?>

                        </div>

                        <div class="entry-summary">

                            <?php the_excerpt(); ?>

                            <?php wp_link_pages( array( 'before' => '<p class="page-links">' . __( 'Pages:', 'oxygen' ), 'after' => '</p>' ) ); ?>

                        </div>

                        <div>

                            <?php userphoto_the_author_thumbnail() ?>

                        </div>




                        <?php do_atomic( 'close_entry' ); // oxygen_close_entry ?>

                    </div><!-- .hentry -->

                    <?php do_atomic( 'after_entry' ); // oxygen_after_entry ?>

                <?php endwhile; ?>

            <?php else : ?>

                <?php get_template_part( 'loop-error' ); // Loads the loop-error.php template. ?>

            <?php endif; ?>

        </div><!-- .hfeed -->

        <?php do_atomic( 'close_content' ); // oxygen_close_content ?>

        <?php get_template_part( 'loop-nav' ); // Loads the loop-nav.php template. ?>

    </div><!-- #content -->

    <?php do_atomic( 'after_content' ); // oxygen_after_content ?>

 <?php get_footer(); // Loads the footer.php template. ?>    

archive.php

<?php
/**
* Archive Template
*
* The archive template is the default template used for archives pages without a more     specific template. 
*
* 
* 
*/

get_header(); // Loads the header.php template. ?>

<div class="aside">

         <?php get_template_part( 'menu', 'secondary' ); // Loads the menu-     secondary.php template.  ?>

    <?php get_sidebar( 'primary' ); // Loads the sidebar-primary.php template.     ?>

</div>

<div class="content-wrap">

    <?php do_atomic( 'before_content' ); // oxygen_before_content ?>

    <div id="content">

        <?php do_atomic( 'open_content' ); // oxygen_open_content ?>

        <div class="hfeed">

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

                <?php while ( have_posts() ) : the_post(); ?>

                    <?php do_atomic( 'before_entry' ); //    oxygen_before_entry ?>

                    <div id="post-<?php the_ID(); ?>" class="<?  php hybrid_entry_class(); ?>">     

                        <?php do_atomic( 'open_entry' ); // oxygen_open_entry ?>

                        <div class="entry-header">

                            <?php echo   apply_atomic_shortcode( 'entry_title', '[entry-title]' ); ?>

                            <?php echo   apply_atomic_shortcode( 'byline', '<div class="byline">' . __( '[entry-published] &middot; by [entry-author] &middot; in [entry-terms taxonomy="category" before=""] [entry-edit-link before=" &middot; "]', 'oxygen' ) . '</div>' ); ?>

                        </div>

                        <div class="entry-summary">

                            <?php the_excerpt(); ?>

                            <?php wp_link_pages( array(   'before' => '<p class="page-links">' . __( 'Pages:', 'oxygen' ), 'after' => '</p>' ) ); ?>

                        </div>

                        <div>

                            <?php   userphoto_the_author_thumbnail() ?>

                        </div>


                        <?php do_atomic( 'close_entry' );   // oxygen_close_entry ?>

                    </div><!-- .hentry -->

                    <?php do_atomic( 'after_entry' ); // oxygen_after_entry ?>

                <?php endwhile; ?>

            <?php else : ?>

                <?php get_template_part( 'loop-error' ); // Loads   the loop-error.php template. ?>

            <?php endif; ?>

        </div><!-- .hfeed -->

        <?php do_atomic( 'close_content' ); // oxygen_close_content ?>

        <?php get_template_part( 'loop-nav' ); // Loads the loop-nav.php template. ?>

    </div><!-- #content -->

    <?php do_atomic( 'after_content' ); // oxygen_after_content ?>

 <?php get_footer(); // Loads the footer.php template. ?>    

empopp-template.php

<?php
 /**
 * Template Name: Employment Opportunities
 *
 * Employment Opportunities Template. Used to display restricted posts with "employment opportunities"
 * category. Category number is 9
 *
 * 
 * 
 */

 get_header(); // Loads the header.php template. ?>

<div class="aside">

    <?php get_template_part( 'menu', 'secondary' ); // Loads the menu-secondary.php template.  ?>

    <?php get_sidebar( 'primary' ); // Loads the sidebar-primary.php template. ?>

</div>

<div class="content-wrap">

    <?php do_atomic( 'before_content' ); // oxygen_before_content ?>

    <div id="content">

        <?php do_atomic( 'open_content' ); // oxygen_open_content ?>

        <div class="hfeed">

            <?php 

                $args = array('cat' => 30);
                $category_posts = new WP_Query($args);

                if($category_posts->have_posts()) : 
                    while($category_posts->have_posts()) : 
                        $category_posts->the_post();
            ?>

                    <?php do_atomic( 'before_entry' ); // oxygen_before_entry ?>

                    <div id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">       

                        <?php do_atomic( 'open_entry' ); // oxygen_open_entry ?>

                        <div class="entry-header">

                            <?php echo apply_atomic_shortcode( 'entry_title', '[entry-title]' ); ?>

                            <?php echo   apply_atomic_shortcode( 'byline', '<div class="byline">' . __( '[entry-published] &middot; by [entry-author] &middot; in [entry-terms taxonomy="category" before=""] [entry-edit-link before=" &middot; "]', 'oxygen' ) . '</div>' ); ?>

                        </div>

                        <div class="entry-summary">

                            <?php the_excerpt(); ?>

                            <?php wp_link_pages( array( 'before' => '<p class="page-links">' . __( 'Pages:', 'oxygen' ), 'after' => '</p>' ) ); ?>

                        </div>

                        <div>

                            <?php     userphoto_the_author_thumbnail() ?>

                        </div>


                        <?php do_atomic( 'close_entry' ); // oxygen_close_entry ?>

                    </div><!-- .hentry -->

                    <?php do_atomic( 'after_entry' ); // oxygen_after_entry ?>

                <?php endwhile; ?>

            <?php else : ?>

                <?php get_template_part( 'loop-error' ); // Loads the loop-error.php template. ?>

            <?php endif; ?>

        </div><!-- .hfeed -->

        <?php do_atomic( 'close_content' ); // oxygen_close_content ?>

        <?php get_template_part( 'loop-nav' ); // Loads the loop-nav.php template. ?>

    </div><!-- #content -->

    <?php do_atomic( 'after_content' ); // oxygen_after_content ?>

<?php get_footer(); // Loads the footer.php template. ?>

The theme I'm using allows for a unique home page where you manually insert posts with various featured images into pre-defined sections. Since this page requires manual post selection, I selected in the settings to have posts go to a separate "news" page. The inclusion/exclusion of a specific category is for specific pages. If I can apply this pre_get_posts to these non-home pages then I should be golden. So far, both the and new one with wp_query is doing the job, but not inheriting the css elements. I really appreciate the help. Thank you. –

The link to the index.php page is http://www.biz.uiowa.edu/bta/news/. That is what ideally I would want the formatting to look like. This formatting is matched on searches and archives as well. The page where I applied the category query to is http://www.biz.uiowa.edu/bta/test/. Thank you for your time.

Could someone please let me know if I've perhaps used the query_posts incorrectly or alternate code to use wp_query (if necessary). My main goal is to have the formatting match. The query_posts appears near line 32 or about 1/3rd of the way down.

Thank you for your time.

share|improve this question
    
On empopp-template.php I changed the code <?php query_posts('cat=9'); ?> to <?php $query = new WP_Query('cat=9'); ?> <?php if ($query-> have_posts() ) : ?> <?php while ($query-> have_posts() ) : $query->the_post(); ?>......... It worked in the sense that it only showed posts from category 9, but it did not take the css formatting. –  UkrVolk11 Apr 1 '13 at 22:06
    
"let me know if I've perhaps used the query_posts incorrectly"-- using query_posts at all is using it incorrectly :) Use a new WP_Query object instead or alter the main query with pre_get_posts. –  s_ha_dum Apr 1 '13 at 22:42

1 Answer 1

up vote 1 down vote accepted

1. CSS/HTML issues are off-topic for this site, per the FAQ.

But, have you tried investigating with Firebug or Chrome's dev tools? The answer is obvious in seconds. This page http://www.biz.uiowa.edu/bta/test/ has large headings because of

.singular .entry-title {
  font-size: 2em;
  margin-bottom: 0.3em;
}

Since you are running a second loop on a singular page, the body class issue I proposed in the comments is catching you.

2. To best exclude a category from the index loop you should use pre_get_posts.

    function wpa_94196_exclude_category( $query ) {

      if ( is_home() && is_main_query() ) {
        set_query_var( 'cat', '-9' );
      }

    }

    add_action( 'pre_get_posts', 'wpa_94196_exclude_category' );
share|improve this answer
    
Would I add this code to the functions.php or could I add this code to the specific pages/templates like index.php and empopp-template.php in my case (to be able to target specific pages)? My index page is not set as a home page. Or would I need to use some type of template tag instead of "is_home()" and instead refer to a page id or name? –  UkrVolk11 Apr 2 '13 at 17:14
    
What's the reason you need a custom page as your homepage if you are just listing all your posts? That's the point of index.php. Apologies if that isn't what you are doing, but you've posted a lot of code and I didn't read it all. This would go in your functions.php but it won't work on a static page as your homepage, not even with adjusted conditionals since it effects the query object before the query is run... so on a static page the query represents that particular page. –  helgatheviking Apr 2 '13 at 18:24
    
The theme I'm using allows for a unique home page where you manually insert posts with various featured images into pre-defined sections. Since this page requires manual post selection, I selected in the settings to have posts go to a separate "news" page. The inclusion/exclusion of a specific category is for specific pages. If I can apply this pre_get_posts to these non-home pages then I should be golden. So far, both the <?php query_posts('cat=9'); ?> and new one with wp_query is doing the job, but not inheriting the css elements. I really appreciate the help. Thank you. –  UkrVolk11 Apr 2 '13 at 19:07
    
Let me rephrase the question about the css. Would the placement or syntax of the wp_query or query_posts (to get a specific category on a specific page) affect whether the php elements of the page template are used or not? Thank you for your time. –  UkrVolk11 Apr 3 '13 at 16:54
    
You should edit your question with your re-phrasing so others can see it too. The first thing that comes to mind that would effect your CSS would be dynamic body classes... so a .blog or something on the blog index could be styled with .blog h1 { color: red; } and it wouldn't apply to your template page. Hard to tell because you didn't provide any links. –  helgatheviking Apr 3 '13 at 16:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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