• Hi folks –

    I have a question about getting content outside the loop. I have a “News” Box and I want to have the possibility to add news to this box out of the backend.

    I found this code here:

    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'NEWS', true);
    wp_reset_query();
    ?>

    It works when I release a new post in which I put a custom field called “NEWS”, but I don’t understand how I can just post “news” to the box, without releasing a new “post”.

    Any hints, ideas?

    Thank you!

    AD

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try it with get_posts. With WordPress you have to post new posts/pages to show content on a website.

    Thread Starter arthurdent2003

    (@arthurdent2003)

    Thank you keesiemeijer,

    …but I don’t get it working.

    I tried something like:

    <?php
    $my_id = 7;
    $post_id_7 = get_post($my_id, ARRAY_A);
    $title = $post_id_7['post_title'];
    ?>

    where I changed the ID to the post ID.

    but it didn’t work for me…

    ….

    Thank you!

    AD

    Moderator keesiemeijer

    (@keesiemeijer)

    try it with this:

    <?php
    $newsposts = get_posts('numberposts=1&meta_key=NEWS');
    setup_postdata($newsposts[0]);
    the_content();
    ?>

    This will show the content of the last post with a custom field called “NEWS”

    This is what I use, not sure how much of it would be useful to you so i pulled the complete code. I changed the name to News for you…this is between my <div> content bracket and the <div> post title bracket on every page I have. blog.compacc.com, I have only certain categories every link and those are even broken down. the posts on my main page only show there and not in our products review pages and stuff like that.

    <div class="column">
    	<?php $postcount = "0"; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	query_posts('category_name=News&paged=' . $paged);// reset post counter ?>
    	<?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
              <?php $postcount++; // post counter ?>
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    Thread Starter arthurdent2003

    (@arthurdent2003)

    Hi People! Thank your very much for the reply! I will check it out!

    Thank you!!!

    AD

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Content in a div box in e.g. HEADER – outside loop’ is closed to new replies.