如果頁面 URL/slug 包含 -nv/,WordPress 如何過濾要顯示的頁面
現在它顯示了網站上的所有頁面,問題是如何過濾它以僅顯示包含 -nv/的頁面 這部分 URL 是唯一的,并且與我需要顯示的所有頁面匹配
?><style>
table {
counter-reset: rowNumber;
}
table tr:not(:first-child) {
counter-increment: rowNumber;
}
table tr td:first-child::before {
content: counter(rowNumber);
min-width: 1em;
margin-right: 0.5em;
color: #cfcfcf;
}</style>
<table>
<tr>
<th>id</th>
<th>title</th>
<th>url</th>
</tr>
<?php // Query for listing all pages in the select box loop
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query( array(
'post_type' => 'page',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC', // or DESC
));
foreach ($all_wp_pages as $value){
$post = get_page($value);
$title = $post->post_title;
$id = $post->ID;
?>
<tr>
<?php echo '<td>' . $id. '</td>
<td>' . $title . '</td>
<td>';
global $post;
if ( $post) { ?>
<?php echo get_permalink( $id ); ?></td>
<?php }
}; ?>
</tr>
</table>
提前謝謝你,因為你很有幫助。
uj5u.com熱心網友回復:
檢查 post slug 是否包含-nvusingstr_contains()功能。
在 foreach 回圈中試用此代碼$id。
$slug = $post->post_name;
if (!str_contains($slug, '-nv')) {
continue;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/532803.html
標籤:phpWordPress
上一篇:為什么我得到UncaughtTypeError:Cannotsetpropertiesofundefined(setting'src')?
