WordPress.org

Ready to get started?Download WordPress

Forums

Excluding post categories fra index.php / including post categories in blog.php (9 posts)

  1. haervaerk
    Member
    Posted 3 years ago #

    I run my site as a standard blog (http://www.haervaerk.dk), where I post stuff that's only related to my art.

    However

    I'd like to have a page on my site called "blog", where I can post stuff which is not directly related to my art: interviews with other artists, reviews of exhibitions etc.

    I've duplicated the index.php and renamed it blog.php, and created a page using the costum template "blog".

    I've also made a new category called "blog"

    I'd like every post with the "blog" category to show up on my "blog" page, but not on my frontpage (where all the stuff related to my personal art is posted)

    How do I make this work?

  2. David Gwyer
    Member
    Posted 3 years ago #

    You can see the following page for details on how to show/hide specific categories etc.

    http://codex.wordpress.org/Function_Reference/query_posts#Exclude_Categories_From_Your_Home_Page

  3. haervaerk
    Member
    Posted 3 years ago #

    Great.

    Do you know where I should put the code:

    <?php
    if ( is_home() ) {
    query_posts( 'cat=-26' );
    }
    ?>

    My index-php looks like this:

    <?php get_header(); ?>
    <div id="content-body">
    <?php if (function_exists('wp_snap')) { echo wp_snap(); } ?>
    <?php if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb('<p id="breadcrumbs">','</p>'); } ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div <?php if (function_exists("post_class")) post_class(); else print 'class="post"'; ?> id="post-<?php the_ID(); ?>">
    <?php lw_show_sidebox(); ?>
    <h2>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></h2>
    <?php lw_simple_date(); ?>
    <?php if ($lw_post_author == "Main page" || $lw_post_author == "Both") : ?>
    <div class="about_author clear">
    <span class="alignleft"><?php echo get_avatar( get_the_author_id(), '20' ); ?></span>
    <div class="alignleft" style="width:470px;"><h4><?php _e('Posted by','lightword'); ?> "><?php the_author(); ?></h4><?php // the_author_description(); if(!get_the_author_description()) _e('No description. Please complete your profile.','lightword'); ?></div><div class="clear"></div>
    </div>
    <?php comments_template(); ?>
    <?php endif; ?>
    <?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { the_post_thumbnail(array( 200,200 ), array( 'class' => 'alignleft' )); } ?>
    <?php the_content(''); ?>
    <?php if(function_exists('wp_print')) { print_link(); } ?>
    <?php wp_link_pages('before=<div class="nav_link">'.__('PAGES','lightword').': &after=</div>&next_or_number=number&pagelink=<span class="page_number">%</span>'); ?>
    <div class="cat_tags clear">
    <span class="category"><?php if($lw_disable_tags == "true" || !get_the_tags()) { _e('Filed under:','lightword'); echo " "; the_category(', ');} else if (get_the_tags() && $lw_disable_tags == "false") { _e('Tagged as:','lightword'); echo " "; the_tags(''); } ?></span>
    <span class="continue"><?php $pos = strpos($post->post_content, '<!--more-->'); if($pos==''){ ?>#comments"><?php if(fb_get_comment_type_count('comment')==1) _e('1 Comment','lightword'); elseif('open' != $post->comment_status) _e('Comments Off','lightword'); elseif(fb_get_comment_type_count('comment') == 0) _e('No Comments','lightword'); else echo fb_get_comment_type_count('comment')." ".__('Comments','lightword'); ?><?php }else{ ?> <?php the_title(); ?>" href="<?php the_permalink() ?>#more-<?php echo $id; ?>"><?php _e('Continue reading','lightword'); ?><?php } ?></span><div class="clear"></div>
    </div>
    <div class="cat_tags_close"></div>
    </div>
    <?php endwhile; else: ?>
    <h2><?php _e('Not Found','lightword'); ?></h2>
    <p><?php _e("Sorry, but you are looking for something that isn't here.","lightword"); ?></p>
    <?php endif; ?>
    <?php
    if ( !function_exists('wp_pagenavi') ) {
    ?>
    <div class="newer_older">
    <span class="newer"> <?php previous_posts_link(__('« Newer Entries','lightword')) ?></span>
    <span class="older"> <?php next_posts_link(__('Older Entries »','lightword')) ?></span>
    </div>
    <?php
    }else{
    wp_pagenavi();
    }
    ?>
    </div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

  4. haervaerk
    Member
    Posted 3 years ago #

    Oh, I got the index.php to exclude posts with the blog-category!

    So far so good.

    Now I need the to show up on my blog page (blog.php) which is currently empty.

    Any ideas?

  5. haervaerk
    Member
    Posted 3 years ago #

  6. haervaerk
    Member
    Posted 3 years ago #

    The code for the blog-page looks like this:

    <?php
    /*
    Template Name: Blog
    */

    // Which page of the blog are we on?
    $paged = get_query_var('paged');
    query_posts('cat=-0&paged='.$paged);

    // make posts print only the first part with a link to rest of the post.
    global $more;
    $more = 0;

    //load index to show blog
    load_template(TEMPLATEPATH . '/index.php');
    ?>

    I'd like to exclude all categories exept "26" which is the category ID for "Blog"

  7. David Gwyer
    Member
    Posted 3 years ago #

    The previous page I linked to has this information on the Category Parameters section:

    http://codex.wordpress.org/Function_Reference/query_posts#Category_Parameters

  8. haervaerk
    Member
    Posted 3 years ago #

    It works! Thanks a lot!

    Cheers

  9. haervaerk
    Member
    Posted 3 years ago #

    Darn - now I can't click "older entries"; it keeps showing the same recent posts. Any ideas?

    Cheers

Topic Closed

This topic has been closed to new replies.

About this Topic