Wordpress Problem, Manipulating Images

Asked

Viewed 46 times

0

I need to do the following, take the news content and its images of a page and show on the main page(Bs the current news, and this page is not in WP only the others) follows the images with the detailed explanation

This is the main page, where there is news that has the image news I have to show the latest news from the other pages that have the image below this

ali onde tem news tenho que colocar as imagens das noticias e o link

Pegar essas noticias e imagens

e essas daqui entre outras paginas

briefly: I have to take the links and images of the news from the other pages, and show in this index

Obs: I had failed attempts by the bank, using this function

     $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
     ");

added a WHERE post_mime_type = 'image/jpeg' and returned images however all the images of the pages, have a way for me to pick up only from the news categories?

  • From what I understand, you want to take some of the content from other pages to show in the initial. Like the 6 latest published news will appear at the top. That’s it?

  • @Hamurabiaraujo That’s right

1 answer

3


To list a post of a particular type or category, you don’t need to scroll down to the level of creating a query itself. wp has functions that abstract this. All this can be done using the class Wp_query.

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, behind everything are posts, with the use of this class it is possible to search for posts from a specific category, pages, images or inserted files, types of custom posts, etc..

Other alternatives

  • wp_get_recent_posts() : A slightly higher level possibility than Wp_query, which allows for simpler and straightforward code. Example of use:

    $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() : Very similar to the previous one, presenting more search parameters, consequently, more flexibility and scope. Example of use:

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

OBS: Examples taken from the documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.