Exclude one headline post from frontpage but not if is paged

von Joern am 2. Dez. 2012 | Keine Kommentare

The problem: I got a WordPress site with feature headline, the latest post of headline category.
Below I want to show all posts from all categories except this one.
But I want to display older posts from this category headline together with any post of any other category.
Next problem with this site, on frontpage have to be 6 posts plus the headline, on following pages is no headline and there should be displayed more posts.

Live on Great Geadgets

This is how I solved this problem for me, the name for that headline category is Headline with ID 6.

the first loop:
<?php get_header(); ?>
<?php if(!is_paged()) { ?>

<?php query_posts(„showposts=1&category_name=Headline“); //retrieves 1 post from headline ?>
<?php while (have_posts()) : the_post(); ?>
<?php $do_not_duplicate = $post->ID; ?>

now do stuff for first post like title and content

<?php endwhile; ?>

<?php } //end if is only not paged headline post ?>

Now I start a loop quering for all posts and leaving the one above out:

$page = (get_query_var(‚paged‘)) ? get_query_var(‚paged‘) : 1;
$num_of_posts = get_option(‚posts_per_page‘);
if ( !is_paged()){
} else {
query_posts(„paged=$page&posts_per_page=$num_of_posts“); } ?>
<?php $i = 1; ?>
<?php while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
<?php if ( $paged < 2 ) { ?>

now do stuff for first page, limited to 6 post and exclude category Headline (ID 6) from that loop, here is the place to style the frontpage and the way how to display posts.

<?php } else { //now if is paged ?>

do stuff for following pages and take the number of pages from the settings in options

<?php } //end if else paged ?>

<?php endwhile; ?>

<div class=“navigation“> This comes normally close to the end of a template

It would be great to exclude a single post by post ID from the second loop, I did not find an easy way for that yet. I mean something like query_posts and exclude a post by $post->ID what you can get from the first loop

exclude post WordPress tr.v. ex·clud·ed, ex·clud·ing, ex·cludes. 1. To prevent from entering; keep out; bar: a jar sealed to exclude outside air; an immigration policy that excludes unrables. 2. To prevent from being included, considered, or accepted; reject: Synonyms for EXCLUDE: eliminate, ban, prohibit, prevent, bar, except, debar, shut out; Antonyms of EXCLUDE: include, admit, receive, accept, welcome, entertain, embrace, take in Merriam-Webster Logo Menu Toggle Lorsqu’une expression LOD INCLUDE ou est utilisée, la valeur peut changer en fonction de la structure de la vue. Le mot-clé INCLUDE prend le contexte de la vue et ajoute une dimension que le 英語「exclude」の意味・使い方・読み方 | Weblio英和辞書 . 動詞. 〜の 余地 を 与えない, 全く許さない, 考慮しない, 取り上げない, 除く, 排除する, 除外する, 退ける, 抜かす, 無視する, 落とす, 一般人を中に入れない, 特権階級に限る, 締め出す, 閉め出しを食わす. 用例. The cost of borrowing has been d from the Tags: 英語「exclude」の意味・使い方・読み方, weblio英和辞書, まとめ. except:(全体から)~を除いて、~以外. excluding:~を(はじめから)除いて、含まないで、外して. ほかにも「使い分け」をご紹介しています♪. 「except」と「excluding」の使い分け. 「between」と「among」の使い分け. 「increase in」と「increase of」の


Du findest mich auch auf Twitter und Facebook!

Schreibe einen Kommentar

Pflichtfelder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.