Last active
February 16, 2019 14:17
-
-
Save conquistadorjd/3794d12562148cbd70aa6b719aaffd8b to your computer and use it in GitHub Desktop.
WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WordPress Tricks and Hacks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( $the_query->have_posts() ) { | |
echo '<ul>'; | |
while ( $the_query->have_posts() ) { | |
$the_query->the_post(); | |
echo '<li>' . get_the_title() . '</li>'; | |
} | |
echo '</ul>'; | |
/* Restore original Post Data */ | |
wp_reset_postdata(); | |
} else { | |
echo '<p>Sorry, no related articles to display.</p>' | |
// no posts found | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The Query | |
$the_query = new WP_Query( $args ); | |
// The Loop | |
if ( $the_query->have_posts() ) { | |
echo '<ul>'; | |
while ( $the_query->have_posts() ) { | |
$the_query->the_post(); | |
echo '<li>' . get_the_title() . '</li>'; | |
} | |
echo '</ul>'; | |
/* Restore original Post Data */ | |
wp_reset_postdata(); | |
} else { | |
// no posts found | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// the query | |
$the_query = new WP_Query( $args ); ?> | |
<?php if ( $the_query->have_posts() ) : ?> | |
<!-- pagination here --> | |
<!-- the loop --> | |
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?> | |
<h2><?php the_title(); ?></h2> | |
<?php endwhile; ?> | |
<!-- end of the loop --> | |
<!-- pagination here --> | |
<?php wp_reset_postdata(); ?> | |
<?php else : ?> | |
<p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p> | |
<?php endif; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Creating array | |
$args = array( | |
'posts_per_page' => 15, | |
'orderby' => 'date', | |
'order' ='ASC' | |
); | |
// Initiate the custom query | |
$custom_query = new WP_Query( $args ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment