WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] theme building wp_query

[Resolved] theme building wp_query

  • hello thank for the helpers

    i want to get the latest six posts but my code its not working for me please help
    heres my code

    $home_query = new WP_Query( ‘posts_per_page=6’ );
    $post_count = 0;
    if ( $home_query -> have_posts() ) : while ( $home_query -> have_posts() ) : $home_query -> the_post();?>

    <?php $args = array(
    ‘post_type’ => ‘attachment’,
    ‘numberposts’ => -1,
    ‘post_status’ => null,
    ‘post_parent’ => $post->ID
    );

    $attachments = get_posts( $args );
    if ( $attachments ) {
    foreach ( $attachments as $attachment ) {
    $alt = trim(strip_tags( get_post_meta($attachment->ID, ‘_wp_attachment_image_alt’, true) ));
    $image_title = $attachment->post_title;
    $caption = $attachment->post_excerpt;
    $description = $image->post_content;
    $default_attr = array(
    ‘src’ => $src,
    ‘class’ => “attachment-$size”,
    ‘alt’ => trim(strip_tags( get_post_meta($attachment->ID, ‘_wp_attachment_image_alt’, true) )),
    );?>
    <?php
    if( !( $post_count % 3 )){ ?> <div class=”posts-wrapper row”> <?php } $post_count++; ?>

    <article <?php post_class(); ?> id=”post-<?php the_ID(); ?>”>
    <div class=”post-thumbnail”>
    <?php if( has_post_thumbnail($post->ID)){?>
    a href=”<?php echo wp_get_attachment_url( $attachment->ID);?>” data-lightbox=”<?php $category = get_the_category(get_the_ID());
    if($category[0]){echo ($category[0]->cat_name);}?>” data-title=”<?php echo $image_title;?>”><?php echo wp_get_attachment_image( $attachment->ID, array(220,300), $default_attr ); ?> a
    and so on

    im traing to build boxs of posts with thumbnails each row hes 3 boxs and i wont the last six it working with category but not witeout

    $home_query = new WP_Query( ‘category_name=front-page&&posts_per_page=6’ );//this is working

    thank for answers

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] theme building wp_query’ is closed to new replies.