0

i've got several posts which are tagged with "design", but also a page called "design".

my question: i put some text into the design-page and would then display all posts which are tagged by "design". how is that possible? can i put a placeholder directly into the text or do i have to code it by myself in php?

thx

3 Answers 3

2

You could easily modify the page template of your theme to include a section that reads "Related Posts" at the bottom and then execute a simple PHP query to get posts as follows:

<?php query_posts('category_name=wordpress&showposts=5'); ?>
<?php while (have_posts()) : the_post(); ?>
   <li>
      <a href="<?php the_permalink(); ?>">
      <?php the_title(); ?>
      </a>
   </li>
<?php endwhile; ?>

You'd need to tweak the category accordingly, and you could always format the post listing the way you want.

1

Easiest way would be to turn your 'Design' tag into a 'Design' Category and then use the Category archive page as the page by putting your page content into the Category description (although that lacks the rich text editor by default) and adjusting your theme to format it nicely.

0

Use a page template to do a regular loop, then create a new WP_Query object and fetch posts with a tag that matches the page name(ie. the slug).

Here's one i prepared earlier..

<?php
/**
  * Template Name: Page with tagged Posts
  */
get_header();
?>

<div id="container">
    <div id="content">
        <?php the_post(); ?>
        <div <?php post_class(); ?>>
            <h2 class="entry-title">
                <?php the_title();?>
            </h2>
            <div class="entry-content">
                <?php the_content(); ?>
            </div>
        </div>

        <?php 
        $tagged_posts = new WP_Query; 
        $tagged_posts->query( array( 'tag__slug_in' => array( $post->post_name ) ) ); 

        if( $tagged_posts->have_posts() ) :
            while( $tagged_posts->have_posts() ) : $tagged_posts->the_post();
            ?>

                <div <?php post_class(); ?>>
                    <h2 class="entry-title">
                        <?php the_title();?>
                    </h2>
                    <div class="entry-content">
                        <?php the_content(); ?>
                    </div>
                </div>

            <?php
            endwhile;
        endif;

        wp_reset_query();
        ?>

    </div>
</div>
<?php //get_sidebar(); ?>
<?php get_footer(); ?>

Hope that helps..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.