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.
- 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] · by [entry-author] · in [entry-terms taxonomy="category" before=""] [entry-edit-link before=" · "]', '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] · by [entry-author] · in [entry-terms taxonomy="category" before=""] [entry-edit-link before=" · "]', '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] · by [entry-author] · in [entry-terms taxonomy="category" before=""] [entry-edit-link before=" · "]', '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.
<?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.query_posts
at all is using it incorrectly :) Use a newWP_Query
object instead or alter the main query withpre_get_posts
.