[英]List posts by wordpress number
I'm breaking my head to make this code work, see.我正在努力让这段代码工作,看。
I can list my wordpress articles by letter.我可以逐个列出我的 wordpress 文章。
But I can't do the same so that it shows articles that start with numbers.但我不能这样做,以便它显示以数字开头的文章。
See my code查看我的代码
<ul>
<?php
//get all post IDs for posts beginning with cap B, in title order,
//display posts
$first_char = '0';
$postids=$wpdb->get_col($wpdb->prepare("
SELECT ID
FROM $wpdb->posts
WHERE SUBSTR($wpdb->posts.post_title,1,1) = %s
ORDER BY $wpdb->posts.post_title",$first_char));
if ($postids) {
$args=array(
'post__in' => $postids,
'post_type' => ' ',
'tag' => 'anime-dublado',
'orderby' => 'title',
'order' => 'ASC',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo ' '. $first_char;
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<style>
.thumbnail{
position:
z-index: 0;
}
.thumbnail:hover{
background-color:
z-index: 50;
}
.thumbnail span{ /*CSS for enlarged image*/
position: fixed;
margin-top: 190px;
background-color: #d3d5d9;
padding: 5px;
left: -1000px;
border: 0px dashed gray;
visibility: hidden;
color: black;
text-decoration: none;
}
.thumbnail span img{ /*CSS for enlarged image*/
border-width: 0;
padding: 2px;
}
.thumbnail:hover span{ /*CSS for enlarged image on hover*/
visibility: visible;
top: 0;
left: 360px; /*position where enlarged image should offset horizontally */
}
</style>
<li>
<div class="manga-body">
<div class="thumb">
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"></a>
<?php if ( has_post_thumbnail() ) { the_post_thumbnail(); }?>
<a class="thumbnail" href="#thumb">
<?php echo catch_that_image(52, 50) ?>
<span>
<?php echo catch_that_image(auto, auto) ?>
</span>
</a>
</div>
<div class="manga-list">
<h2> <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
</div>
<div class="" style="font-weight: margin-top: 20px;">
<div class="waktu"></div>
</div>
</div>
</li>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
}
?>
</ul>
I already tried to change that part $ first_char = '0-9';我已经尝试改变那部分 $ first_char = '0-9'; for only one number but only 1 article appears.只有一个数字,但只出现 1 篇文章。
I would like the code to show all articles that start with numbers only.我希望代码显示所有仅以数字开头的文章。
I could get it to work if I could put in that code $ first_char = '0,1,2,3,4,5,6,7,8,9,';如果我可以输入该代码,我可以让它工作 $ first_char = '0,1,2,3,4,5,6,7,8,9,'; but I can't do that但我不能那样做
Maybe this work:也许这项工作:
$first_char = "('0','1','2','3','4','5','6','7','8','9')";
And in the SQL query change " = " for " IN "并在 SQL 查询中更改“ = ”为“ IN ”
WHERE SUBSTR($wpdb->posts.post_title,1,1) IN %s
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.