Forums

[resolved] query_post('tag= I can only find unresolved topics (11 posts)

  1. JamieLL
    Member
    Posted 9 months ago #

    Thanks in advance for any help offered!

    Using the Loop, I'm trying to post blog entries by tag. I've tried various adjustments but it's getting nothing. My best stab is as follows:

    <?php
    $tag="folding-chairs";
    require_once($_SERVER['DOCUMENT_ROOT'].'/blog/wp-blog-header.php');
    query_posts('tag='.$tag);
    while (have_posts()) : the_post();
    echo the_content();
    endwhile;
    ?>

    Can anyone tell me where I'm getting this wrong?

    Thanks,
    Jamie

  2. Sam Scholfield
    Member
    Posted 9 months ago #

    the_content(); doesn't need to be echo'd out. Other than that it looks fine. Try it out without the require_once(); if your still having problems.

    ?php
    $tag="folding-chairs";
    
    // retrieve one post with a tag of folding-chairs
    query_posts( 'tag='.$tag );
    
    // the Loop
    while (have_posts()) : the_post();
    	the_content();
    endwhile;
    ?>
  3. JamieLL
    Member
    Posted 9 months ago #

    Thanks for your help. This continues- you can see my test page here...

    I removed the require_once(); and it killed the page - I'm pretty sure this is needed as this is the only reference to my WP blog in the page.

    I've tried a few different methods, and yours works - if I change the_content() to the_title()

    It works fine with the_title() but I need the_content()

    Seems very strange! Any ideas?

  4. Sam Scholfield
    Member
    Posted 9 months ago #

    try adding

    global $more;
    $more = 1;

    above the_content();

    1 will display ALL of the content,
    0 will display some of the content, but you will need to change the_content() to something like the_content('more...');

    Beyond that, I'm not sure, it seems like an odd issue.

  5. JamieLL
    Member
    Posted 9 months ago #

    Thanks again. I now have...

    [please read http://codex.wordpress.org/Forum_Welcome#Posting_Code ]

    $tag="folding-chairs";
    
    // retrieve one post with a tag of folding-chairs
    query_posts( 'tag='.$tag );
    
    // the Loop
    while (have_posts()) : the_post();
    global $more;
    $more = 1;
    the_content('more...');
    endwhile;

    still not working.

    I'm wanting to pull blog entries with specific tags, into relevant product range pages. I wonder if there is another way around this.

  6. Sam Scholfield
    Member
    Posted 9 months ago #

    ok here is a different solution:

    $tag = 1;
    
        the_content();
    
        query_posts("tag=" . $tag);
    
        if (have_posts()) : while (have_posts()) : the_post(); ?>
            <div id="post-<?php the_ID() ?>">
                <?php the_title(); ?>
                <div class="entry-content">
                    <?php the_excerpt(); ?>
                    <a href="<?php the_permalink(); ?>" class="more">more...</a>
                </div>
            </div><!-- post -->
        <?php endwhile; else: ?>
            <h2>Arg!</h2>
            <p>There are no posts to show!</p>
        <?php endif;
        wp_reset_query();

    Please note that this code is not tested.

    you can also put that into a function:

    function a_tagloop($tag){}

    Give that a try.

  7. JamieLL
    Member
    Posted 9 months ago #

    thanks again.

    It's still only grabbing the_title()

    the_permalink works fine, and the else: works fine, it just won't pick up the_excerpt or the_content.

    I've tested the script on a page which currently works with the following:

    <?php
    require_once($_SERVER['DOCUMENT_ROOT'].'/blog/wp-blog-header.php');
    ?>
    
    <?php query_posts('showposts=1&offset=5'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php the_date(); echo "<br />"; ?>
    <b><a href="/blog.php#<?php the_title(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></b><br />
    <div style="color: #000; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 9pt; margin-left: 10px;"><?php the_excerpt(); ?></div>
    <?php endwhile;?><p>

    any more ideas?

  8. JamieLL
    Member
    Posted 9 months ago #

    just to add (in case it's not clear - I can grab the_excerpt elsewhere on the same page.

  9. Sam Scholfield
    Member
    Posted 9 months ago #

    I just recreated what you are trying to do, however I can't show you as its on a local version.

    This is the code I used:

    function sams_tagloop($tag = 'TAG'){
    
        thematic_postheader();
    
        the_content();
    
        query_posts("tag=" . $tag);
    
        if (have_posts()) : while (have_posts()) : the_post(); ?>
            <div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>">
                <?php thematic_postheader();
                if ($counter == 1 && has_post_thumbnail()){
                    the_post_thumbnail('homepage-thumbnail');
                } ?>
                <div class="entry-content">
                    <?php the_excerpt();?>
                    <a href="<?php the_permalink(); ?>" class="more"><?php echo more_text() ?></a>
                    <?php $counter++; ?>
                </div>
            </div><!-- post -->
        <?php endwhile; else:?>
            <h2>Arg!</h2>
            <p>There are no posts to show!</p>
        <?php endif;
        wp_reset_query();
    }

    You will notice I use the Thematic theme, however if you remove the thematic functions then it will still work. (This code is in the themes function.php file.

    That is called from a template file with the function sams_tagloop('TAG');

    Alternatively, you can use a plugin, e.g. http://wordpress.org/extend/plugins/posts-by-tag/

    That uses a short code [posts-by-tag tags = "tag1, tag2"]

  10. JamieLL
    Member
    Posted 9 months ago #

    Hi Sam,

    I've fixed it... sorry to have wasted your time - it's been great to get a response from you though.

    Last night I managed to display the_content by using ->the_content, however I still couldn't get ->the_excerpt.

    I checked the excerpt column in MySQL and discovered that very few blog posts had an excerpt.

    I've checked through how excerpts work and discovered that there are automatic and manual excerpts working independently. I've changed my WP admin > screen settings and checked the excerpts box - now I have a field to enter excerpts beneath posts, and the script is collecting them ok.

    Thanks again for your help!

  11. Sam Scholfield
    Member
    Posted 9 months ago #

    It's no problem. Glad to hear its fixed!

Reply

You must log in to post.

About this Topic