program development

Wordpress calls a category article code sharing

<? php //cat is the column ID showposts is the number of calls query_posts ('t […]

article directories

<? php
//cat is the column ID showposts is the number of calls
query_posts(‘tag=app&cat=1&showposts=1’);
?>
<ul style=”float:left”>
<? php if (have_posts()) :while (have_posts()) : the_post(); ?>
<li>
<a href=”<? php the_permalink() ?>”><? php the_title(); ?></a><! - Title-&gt;
</li>
<? php endwhile; endif; ?>
</ul>
<? php wp_reset_query(); ?>

The above code is an article calling an app with a label in category id is 1. Not all three attributes tag, cat, and showposts need to be added. You can see if you need to add attributes. If you still want to call the article code with pictures as follows, you need to add it in your function template before adding code.

function catch_that_image() {
global $post, $posts;
$first_img = ”;
ob_start();
ob_end_clean();
$output = preg_match_all(‘/<img.+ src=[‘”]([^'”]+)[‘”].*>/ i’, $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = “/images/default.jpg”;
}
return $first_img;
}

After adding it, the calling code is as follows

 

<? php
//cat is the column ID showposts is the number of calls
query_posts(‘tag=app&showposts=1’);
?>
<ul style=”float:left”>
<? php if (have_posts()) :while (have_posts()) : the_post(); ?>
<li>
<img src=”<? php echo catch_that_image(); ?>”alt=”<? php the_title();?>”width=”228px”,height=”105px”/><! - Thumbnails->
<a href=”<? php the_permalink() ?>”><? php the_title(); ?></a><! - Title-&gt;
</li>
<? php endwhile; endif; ?>
</ul>
<? php wp_reset_query(); ?>