• Hi there,

    Im trying to make a list of post with a specific category.. I want the_content, some text and a custom field with the title displayed.. I havn′t included the custom field yet in the code. I want every post in a section so I can style it proberly.

    At the moment i getting a “unexpected end of file” error.

    Hope anyone can help in here…

    Have a great day

    <div id="main3" class="tencol first clearfix" role="main">
    
     <?php if ( have_posts() ) : while ( have_posts() ) : the_post();
    $args = array('category_name=recipes&showposts=100'.'&orderby=date&order=asc');
    $postlist = get_posts($args);
    foreach ($postlist as $post) {
    setup_postdata($post);
    if (the_content()) {
    echo '<section class="entry-content clearfix">';
    the_content();
    echo '</section>';
    }
    else {
    echo ' ';
    }
    }
    ?>
    
    </div>
Viewing 10 replies - 1 through 10 (of 10 total)
  • Your code has many errors, below is a more accurate version of the same code, make your tests it fits your needs.

    <?php
    $args = array(
    'category_name' => 'recipes',
    'posts_per_page' => 100,
    'orderby' => 'date',
    'order' => 'asc'
    );
    $objPosts = new WP_query( $args );
    if ( $objPost->have_posts() ) : while ( $objPost->have_posts() ) : $objPost->the_post();
    if( !empty( get_the_content() )
    the_content();
    endwhile;
    endif;
    ?>

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Thread Starter johansenkristian

    (@johansenkristian)

    Thank you for replying..

    It gives me at fatal error: Can’t use function return value in write context in this line:

    ‘if( !empty( get_the_content() ) ‘

    Changes that line the code below:

    $content = get_the_content();
    if( !empty( $content ) )

    Thread Starter johansenkristian

    (@johansenkristian)

    Like this? It gives me an unexpected endwhile error

    <?php
    $args = array(
    'category_name' => 'recipes',
    'posts_per_page' => 100,
    'orderby' => 'date',
    'order' => 'asc'
    );
    $objPosts = new WP_query( $args );
    if ( $objPost->have_posts() ) : while ( $objPost->have_posts() ) : $objPost->the_post();
    $content = get_the_content();
    if( !empty( $content ) )
    endwhile;
    endif;
    ?>

    [Moderator Note: Please post code & markup between backticks (not single quotes) or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    you erased more lines that should test the code below:

    <?php
    $args = array(
    'category_name' => 'recipes',
    'posts_per_page' => 100,
    'orderby' => 'date',
    'order' => 'asc'
    );
    $objPosts = new WP_query( $args );
    if ( $objPost->have_posts() ) : while ( $objPost->have_posts() ) : $objPost->the_post();
    $content = get_the_content();
    if( !empty( $content ) )
    the_content();
    endwhile;
    endif;
    ?>
    Thread Starter johansenkristian

    (@johansenkristian)

    Thank again..

    I gives me an notice about undefined variable and fatal error “call to member function have_post() on a non-object in

    if ( $objPost->have_posts() ) : while ( $objPost->have_posts() ) : $objPost->the_post();

    any ideas?

    Thread Starter johansenkristian

    (@johansenkristian)

    Okay i figured out the problem.. It was the name that was wrong $objPosts was $objPost in the if statement..

    But how can I wrap the posts into different sections.? is it possible to add that in the query..

    Thread Starter johansenkristian

    (@johansenkristian)

    And is it possible to add get_post_meta as well to the code?

    The code that was spent just an example for you to see what was wrong with your code, you can now work the way you want.

    Thread Starter johansenkristian

    (@johansenkristian)

    al right.. Thank you for your time.. I’m trying to figure it out..

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘List of posts with content’ is closed to new replies.