• Resolved tylermartin

    (@tylermartin)


    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: https://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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter tylermartin

    (@tylermartin)

    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.

    Thread Starter tylermartin

    (@tylermartin)

    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;
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Fields Outside Post Loop’ is closed to new replies.