-
Notifications
You must be signed in to change notification settings - Fork 0
/
latest_news.php
45 lines (31 loc) · 921 Bytes
/
latest_news.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
// function that runs when shortcode is called
function latest_news_Shortcode() {
ob_start();
// args
$args = array(
'posts_per_page' => 10,
'post_type' => 'post',
'meta_key' => 'latestnews',
'meta_value' => 1
);
// query
$the_query = new WP_Query( $args );
?>
<div class="container">
<?php if( $the_query->have_posts() ): ?>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="text">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</div>
<img src="" />
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php return ob_get_clean(); ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post().
}
// register shortcode
add_shortcode('latest_news', 'latest_news_Shortcode');