WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Fields Outside Post Loop (3 posts)

  1. TylerMartin
    Member
    Posted 8 years ago #

    I want to be able to display custom field data oustide the post loop.

    I have found a "Get Custom Field Values" plugin. That works but it only get the most recent custom field from the database.

    I would like to call and echo the custom field data from the first post that appears on the page you are looking at, but calling it from header.php. This is for a webcomic: http://ontherockscomics.com . I would be setting posts to only one per page, so this would run it like a daily archive. Doing it this way would allow me to keep my current layout. The comic is too wide to insert it in the post loop.

    Thanks in advance.

  2. TylerMartin
    Member
    Posted 8 years ago #

    I'm thinking one way to do this would be with multiple loops.

    I could run 2 post loops. The first one would only show the custom field. Of course there should only be one post anyway so it would show one comic on that page.

    Problem is I would not know how to go about setting up the separate loop that would appear up above the other loop and sidebar.

  3. TylerMartin
    Member
    Posted 8 years ago #

    Well, I found a solution. I run a single-post post loop at the bottom of header.php. I only called up the date in the format I save the comics in with a DOT GIF extension and IMG SRC info surrounding it(For example: 2005-11-05.gif). Then I just set it to one post per page, I suppose you could do one day per page too for multiple posts per comic.

    The code I used. Although I'll probably move the IMG SRC to a subfolder rather than just in root:

    <?php
    $gposts = get_posts('numberposts=1');
    foreach ($posts as $post) :
    ?>

    <?php echo '<img src="' ?>
    <?php the_time('Y-m-d') ?>
    <?php echo '.gif" />' ?>

    <?php
    endforeach;
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic