Recent posts from wordpress gallery

I want to display recent images from wordpress gallery in the format like:

<div class="portfolio-item">
            <div class="portfolio-overlay">
                <a href="HERE LINK ON IMAGE" data-lightbox="image-1" data-title="My caption"><img src="img/zoom.png" width="58" height="58" alt="" title=""></a>
            </div><!-- .portfolio-overlay-->
            <img class="pi-img" src="HERE LINK ON IMAGE" alt="" title="">
        </div><!-- .portfolio-item-->

How i should build my loop? Thank You

Solutions

First of all you should use thumbs for posts (read more about post's thumbs). Than in your category template use this loop:

    <?php if ( have_posts() ) : ?>
    <?php while ( have_posts() ) : the_post(); ?>
        <article class="post">
            <header>
                <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
                <span class="date"><time datetime="<?php the_time('Y-m-d'); ?>"><?php the_time('j F Y'); ?> <?php _e('в');?> <?php the_time('G:i'); ?></time></span>
                <span class="author"><?php _e( 'Author:', 'nikita-sp' ); ?> <?php the_author(); ?></span>
                <span class="category"><?php _e( 'in category', 'nikita-sp' ); ?> <?php the_category(', '); ?></span>
                <span class="comments"><?php comments_popup_link( __( '0 comments', 'nikita-sp' ), __( '1 comment', 'nikita-sp' ), __( '% comments', 'nikita-sp' )); ?></span>
                <?php edit_post_link( "Edit", '<span class="edit">', '</span>'); ?>
            </header>
            <?php the_content('read more...'); ?>
        </article>
    <?php endwhile; ?>
    <?php wp_pagenavi(); ?>
<?php else : ?>
        <article>
            <h2><?php printf( __( 'SEARCH RESULT for: %s' ), '<span>' . esc_html( get_search_query() ) . '</span>' ); ?></h2>
            <p class="center"><?php _e( 'Sorry, nothing was found', 'nikita_sp' ); ?></p>
            <?php get_search_form(); ?>
        </article>
<?php endif; ?>

Also use thumb output where y want.

                <?php if ( has_post_thumbnail()) : ?>
                    <?php the_post_thumbnail(); ?>
            <?php endif; ?>

If you sort the query results

"SELECT * FROM gallery ORDER BY date ASC LIMIT ?"
// where ? is the number of rows you want to return

you can just do a simple foreach loop:

foreach ($galleryPic as &$pic) {
//your code
}
Tags: PHP / Html / Wordpress

Similar questions

JQuery Slideshow only works on the most recent post. Need it to work on most recent posts on homepage
Complete newbie here. I need the following slideshow to work for all recent posts on the homepage (wordpress). Currently, it only works on the most recent post (latest post). Here's my code in content.php: Here's my js code in header.php (Jonathan Snook's code): PS: I know that Snook has multiple slideshow on the same page version but I can't get t...
PHP - Combining recent posts with recent work
i'm trying to pull in 2 seperate feeds onto my wordpress homepage (recent portfolio work & recent blog posts). I want both sets to sit within the same ul. I've managed to pull in the portfolio feed, but i'm having trouble with the blog feed. Can anyone help with getting the post feed to pull? I'm sure this isn't the most efficient way of doing ...
Instagram API to Wordpress - Recent Photos Aren't Most Recent
I've got this working to pull recent Instagram posts into Wordpress, however the "recent" photos that are displayed aren't actually my most recent Instagram posts. When I refresh, the Instagram posts that are pulled in also change. I can only find a max/min time within the API docs. Is there any way to just get the last 3 Instagram posts made?
How to get the 5 most recent comments and each comment 5 most recent replies (children)
I want to get the 5 most recent comments and each comment's 5 most recent replies (children) in descending order. With the following code I can get the 5 most recents comments but it won't distinguish comments from replies which results in a list of comments independently of their 'type' (comment or reply). How can I do this?
ACF - Gallery Field -> reverse lookup to find all posts where that image is in the Gallery Field
I am trying to do a reverse query to show me all of the posts that an image may be attached to using the ID of that image. The kicker is, the connection would be done using the ACF Gallery Field https://www.advancedcustomfields.com/resources/gallery/ I have the ID's of the images noticed there was a meta data field for ["uploaded_to"] tha...
Can I create a NextGen gallery from a WordPress gallery
Is it possible to convert a standard WordPress gallery that I have created in a page to a NextGen Gallery? And if so, how do I do this?

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.