Wordpress problem, Manipulating images

0

I need to do the following, take the news content and your images from a page and show it on the main page (obs the current news, and this page is not in the WP only the others) follow the images with the detailed explanation

This is the main page, here where you have news that is with the news image I have to show the last news of the other pages that have the image below

Briefly:Ihavetogetthelinksandimagesofthenewsfromtheotherpages,andshowinthisindex

obs:Ihavefailedattemptsbythebank,usingthisfunction

$sql=mysql_query("SELECT DISTINCT wposts.* FROM wp_3_posts wposts 
     LEFT JOIN wp_3_postmeta wpostmeta ON wposts.ID = wpostmeta.post_id 
     LEFT JOIN wp_3_term_relationships ON (wposts.ID =                            
     wp_3_term_relationships.object_id) 
     LEFT JOIN wp_3_term_taxonomy ON          
     (wp_3_term_relationships.term_taxonomy_id =          
     wp_3_term_taxonomy.term_taxonomy_id) 

     union 
     SELECT DISTINCT wposts.* FROM wp_4_posts wposts 
     LEFT JOIN wp_4_postmeta wpostmeta ON wposts.ID = wpostmeta.post_id 
     LEFT JOIN wp_4_term_relationships ON (wposts.ID =          
     wp_4_term_relationships.object_id) 
     LEFT JOIN wp_4_term_taxonomy ON          
     (wp_4_term_relationships.term_taxonomy_id = 
     wp_4_term_taxonomy.term_taxonomy_id) 

     union 
     SELECT DISTINCT wposts.* FROM wp_5_posts wposts 
     LEFT JOIN wp_5_postmeta wpostmeta ON wposts.ID = wpostmeta.post_id 
     LEFT JOIN wp_5_term_relationships ON (wposts.ID =          
     wp_5_term_relationships.object_id) 
     LEFT JOIN wp_5_term_taxonomy ON          
     (wp_5_term_relationships.term_taxonomy_id = 
     wp_5_term_taxonomy.term_taxonomy_id)

     limit 6
     ");

I added a WHERE post_mime_type = 'image/jpeg' and returned images but all the images on the pages, is there a way I can get only news categories?

    
asked by anonymous 16.03.2017 / 13:04

1 answer

3

To make the post listing of a particular type or category, you do not have to go down to the level of creating a query itself. Wp has functions that abstract this. All of this can be done using the class WP_Query .

The basic use of the WP_Query class:

<?php

    // Inicialização do objeto WP_Query com os parâmetros da busca($args)
    $the_query = new WP_Query( $args );

    // O loop para percorrer os resultados da query
    if ( $the_query->have_posts() ) {
        echo '<ul>';
        while ( $the_query->have_posts() ) {
            $the_query->the_post();
            echo '<li>' . get_the_title() . '</li>';
        }
        echo '</ul>';
    } else {
        echo 'Sem conteúdo!';
    }
    wp_reset_postdata();

As in wp, from behind, everything is posts, using this class you can search for posts from a specific category , pages , images or files inserted , custom post types , etc.

Other alternatives

  • wp_get_recent_posts () : A possibility a little higher level than WP_Query, which allows a simpler and more straightforward code. Example usage:

    $args = array( 'numberposts' => '5' );
    $recent_posts = wp_get_recent_posts( $args );
    foreach( $recent_posts as $recent ){
        echo '<li><a href="' . get_permalink($recent["ID"]) . '">' .   $recent["post_title"].'</a> </li> ';
    }
    wp_reset_query();
    
  • get_posts () : Much like the previous one, with more search parameters, therefore, more flexibility and comprehensiveness. Example usage:

    <?php
    global $post;
    $args = array( 'posts_per_page' => 10, 'order'=> 'ASC', 'orderby' => 'title' );
    $postslist = get_posts( $args );
    foreach ( $postslist as $post ) :
        setup_postdata( $post ); ?> 
        <div>
            <?php the_date(); ?>
            <br />
            <?php the_title(); ?>   
            <?php the_excerpt(); ?>
        </div>
    <?php
        endforeach; 
        wp_reset_postdata();
    ?>
    

NOTE: Examples taken from the documentation.

    
16.03.2017 / 14:54