Display Wordpress Messages on Two Pages

I have three pages on my site. Name them at home, page 2 and page 3. My "home" page is set as a static front page. My page2 is configured as a blog page.

I want the following:

I want page2 to display blog posts with a specific category (of which ID is known).

and

I want page3 to display blog posts with a specific category (of which ID is known).

The PHP code that only shows messages with a specific category (or, in my case, actually shows messages, excluding two categories) is as follows:

<?php query_posts($query_string . '&cat=-3,-8'); ?>
<?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
        <div class="post" id="post-<?php the_ID(); ?>">
        <h3><a href="<?php the_permalink() ?>" rel="bookmark"
            title="Permanent Link to <?php the_title_attribute(); ?>">
            <?php the_title(); ?></a></h3>
        <?php the_excerpt('Read the rest of this entry &raquo;'); ?>
        </div><!-- /.post-->

Now, in my page.php, I have the following code to display posts with one category:

<?php
    // BEGIN IF PAGE is newspaper articles page
    if ( is_page('newspaper') ) {

        //BEGIN POST REGION

        query_posts($query_string . '&cat=8'); ?>
        <?php if (have_posts()) : ?>
            <?php while (have_posts()) : the_post(); ?>
                <div class="post" id="post-<?php the_ID(); ?>">
                <h3><?php the_title(); ?></h3>

                <?php the_content('Read more &raquo;'); ?>


                </div><!-- /.post-->

            <?php endwhile; ?>

        <?php else : ?>

        <?php endif; ?>

        <?php

    } //end if is_page
?>

( .3 ). ( index.php).

EDIT: ( ). index.php:

<?php
if ( is_page('newspaper') || is_home() ) { // START if is home

?>
<?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
        <div class="post" id="post-<?php the_ID(); ?>">
            <h3><a href="<?php the_permalink() ?>" rel="bookmark"
                title="Permanent Link to
                <?php the_title_attribute(); ?>">
                <?php the_title(); ?></a></h3>

            <!--<p><?php the_time('F jS, Y') ?> <?php //the_author() ?></p>-->

            <?php the_excerpt('Read the rest of this entry &raquo;'); ?>


        </div><!-- /.post-->

    <?php endwhile; ?>

<?php else : ?>

<?php endif; ?>

<?php
} //end if is_home() or is_page()
?>

, , ...

( ). , ?

! Amit

+3
4

Wordpress , :

<?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h3><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a></h3>
<?php the_excerpt('Read the rest of this entry &raquo;'); ?>
<?php endwhile; ?>

WP / . ( php, /). / WP" WordPress

, : "WordPress Codex, WP , , : " WordPress Codex.

+3

I think this topic answers the question and does what you want. http://wordpress.org/support/topic/show-only-x-category-posts-on-page?replies=9#post-1053767

0
source

Using the string “newspaper” in is_page is a potential source of the problem. It may be spelled incorrectly. Have you ever tried using the page id? Sort of

is_page('999')
0
source

Source: https://habr.com/ru/post/1757622/


All Articles