Note that there are some explanatory texts on larger screens.

plurals
  1. POShowing Wordpress posts on two pages
    text
    copied!<p>I have three pages on my site. Let's call them home, page2, and page3. My 'home' page is set as a static front page. My 'page2' is set up as the blog page. </p> <p>What I want is the following:</p> <p>I want page2 to display blog posts with a certain category (of which ID is known).</p> <p>AND</p> <p>I want page3 to display blog posts with a certain category (of which ID is known).</p> <p>The PHP code to only show posts with a certain category (or actually in my case, show posts excluding two categories) is the following:</p> <pre><code>&lt;?php query_posts($query_string . '&amp;cat=-3,-8'); ?&gt; &lt;?php if (have_posts()) : ?&gt; &lt;?php while (have_posts()) : the_post(); ?&gt; &lt;div class="post" id="post-&lt;?php the_ID(); ?&gt;"&gt; &lt;h3&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title_attribute(); ?&gt;"&gt; &lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h3&gt; &lt;?php the_excerpt('Read the rest of this entry &amp;raquo;'); ?&gt; &lt;/div&gt;&lt;!-- /.post--&gt; </code></pre> <p>Now, in my page.php, I have the following code to display posts with one category:</p> <pre><code>&lt;?php // BEGIN IF PAGE is newspaper articles page if ( is_page('newspaper') ) { //BEGIN POST REGION query_posts($query_string . '&amp;cat=8'); ?&gt; &lt;?php if (have_posts()) : ?&gt; &lt;?php while (have_posts()) : the_post(); ?&gt; &lt;div class="post" id="post-&lt;?php the_ID(); ?&gt;"&gt; &lt;h3&gt;&lt;?php the_title(); ?&gt;&lt;/h3&gt; &lt;?php the_content('Read more &amp;raquo;'); ?&gt; &lt;/div&gt;&lt;!-- /.post--&gt; &lt;?php endwhile; ?&gt; &lt;?php else : ?&gt; &lt;?php endif; ?&gt; &lt;?php } //end if is_page ?&gt; </code></pre> <p>But it doesn't show the proper posts on the newspaper page (or page3 in this question). It does, however, work for the articles page (main index.php blog page). </p> <p>EDIT: I've also tried the following (but it doesn't work). I put this in the index.php file:</p> <pre><code>&lt;?php if ( is_page('newspaper') || is_home() ) { // START if is home ?&gt; &lt;?php if (have_posts()) : ?&gt; &lt;?php while (have_posts()) : the_post(); ?&gt; &lt;div class="post" id="post-&lt;?php the_ID(); ?&gt;"&gt; &lt;h3&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title_attribute(); ?&gt;"&gt; &lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h3&gt; &lt;!--&lt;p&gt;&lt;?php the_time('F jS, Y') ?&gt; &lt;?php //the_author() ?&gt;&lt;/p&gt;--&gt; &lt;?php the_excerpt('Read the rest of this entry &amp;raquo;'); ?&gt; &lt;/div&gt;&lt;!-- /.post--&gt; &lt;?php endwhile; ?&gt; &lt;?php else : ?&gt; &lt;?php endif; ?&gt; &lt;?php } //end if is_home() or is_page() ?&gt; </code></pre> <p>Again, this shows the posts on the main blog page, but doesn't show any posts on the newspaper page...</p> <p>The question is therefore simple (I think). How do I show posts on another page OTHER than the main blog page?</p> <p>Thanks! Amit</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload