• Resolved Jaaaarne

    (@jaaaarne)


    Hello everyone!

    The more I dig into WP, the more I see how flexible it can be. So I’m pretty sure it can do the trick I need it to do. Thing is, I’m not sure how to go about doing it, so hope someone could point me in the right direction.

    What I need to do is list blog entries (well, not the whole entries, but this part is easy) by the particular tag on the “static” WP page.

    For example, there is a static page called, um, “Mary Sue”. 🙂 It has some text on it, some pictures on it – the usual way. Also there are several blog entries tagged “Mary Sue”. I need to fetch these entries by tag (which is the same as the page title) and list them on the page.

    Is there a way to do that?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Use the template tag, query_posts(), and one of the tag arguments:

    * tag
    * tag__and
    * tag__in
    * tag_slug__and
    * tag_slug__in

    If you want to use the page title to grab posts with tags matching the title, find this in your page.php (assuming you have one).
    <?php endwhile; endif; ?>
    and switch that for..

    <?php endwhile; ?>
    		<?php
    			query_posts('tag='.strtolower(get_the_title()).'&post_type=post');
    			while (have_posts()) : the_post();
    				the_title();
    			endwhile;
    		?>
    		<?php endif; ?>

    Not sure how valid or correct that is, but it does work… (and you’d of course need to add your own markup around the_title() area…

    Thread Starter Jaaaarne

    (@jaaaarne)

    t31os_, I’m afraid I’m either doing something wrong, or it doesn’t work for me. First of all, I don’t have <?php endwhile; endif; ?>. 🙂 There is a “not found” piece of text between <?php endwhile; else: ?> and <?php endif; ?> (I based my theme on Kubrick).

    MichaelH, I’m sorry but I’ve already went through these parts of the Codex before. The problem is, I think I need to put another loop inside existing one. I need WP to fetch the static page’s content and list some blog entries after it at once. Your reply is not helpful at all, because I just don’t know where to start, sorry. 🙁

    I think both MichaelH and t310s_ have shown you the way.

    I’ll try to amplify them a bit.

    1.You create a page template for this purpose in the theme.
    2. There IS the string “<?php endwhile; endif; ?>” in the default theme.
    3. Split them as indicated by t31os_: one loop for fetching the content of the Page another governed by the query – query_posts('tag=Mary Sue');
    4. Add the template tags to suit your requirement – title with the permalink or except or the whole post of those having the tag “Mary Sue”

    Hope I make sense!

    PS: I just tested it in my localhost and it works!

    S.K

    Thread Starter Jaaaarne

    (@jaaaarne)

    I must’ve learnt the query_posts() page by heart by now, but I must be too dumb to make it work. 🙁 Sorry guys. 🙁 Will have to go without it.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘List entries by tag’ is closed to new replies.