Forums

Show TAG related news in static page (6 posts)

  1. amonsul
    Member
    Posted 2 years ago #

    Hi!

    I have a static page and I want this page to show the latest 10 news with the specific tag "xxx". How can I do it?

    Thanks

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Try creating a custom page template that contains a custom query based on get_posts or query_posts. Then apply the new template to your static page.

  3. MichaelH
    Volunteer
    Posted 2 years ago #

    Create a Page Template and assign it to that static page, then use something like:

    <?php
        $args=array(
          'tag__in' => array(3),
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => 10,
          'caller_get_posts'=> 1
          );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          echo 'List of Posts';
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
           <?php
          endwhile;
        }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy
    query_posts()
    How do I determine a Post, Page, Category, Tag, Link, Link Category, or User ID?

  4. amonsul
    Member
    Posted 2 years ago #

    This was fast! Thanks! I will try it...

  5. amonsul
    Member
    Posted 2 years ago #

    Hi Michael! In your code where can I definie that the tag is "xxx"?

  6. MichaelH
    Volunteer
    Posted 2 years ago #

    Read that last link I provided if you don't know the ID of the Tag you want displayed.

Topic Closed

This topic has been closed to new replies.

About this Topic