wordpress 自定义 post 标题查看器开发
wordpress custom post title viewer development
我想在 wordpress 中创建这样的东西,以便在 wordpress 页面中我可以向用户显示链接到他们的 post 链接的 post 标题以及那些 post秒。
我应该在 wordpress 中使用什么样的代码?
我是 wordpress 编码的新手。
所以请给我一些示例代码,以便我可以使用。
我还想从一个特殊类别中选择 posts。我该怎么做?
是否有任何 wordpress 插件可以做到这一点?
分页链接也很重要。
谢谢
我会调查 WP_Query。可能需要一些时间来习惯它,但它可以让您回显所有您想要的数据。我现在几乎什么都用它。
在 $args
数组中定义要查询的内容(例如来自特定类别的 posts,有多少,按什么顺序),然后从那里可以拉出标题、发布日期、附件、摘录、特色图片等。
<?php
// The Query
$args = array(
'numberposts' => '5',
'category_name' => 'my-category', // the slug
'offset' => '0',
'orderby' => 'post_date',
'order' => 'DESC',
'post_status' => 'publish'
);
$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
}
?>
WP_query 的重要之处在于,您可以使用它在 1 个模板上创建多个循环。这将取代模板中的正常循环。
对于日期,您可以使用 the_date() 或 get_the_date()
。所以你可以做一个
echo '<p><span class="date">' . get_the_date() . '</span> <a class="my-title" href="' . get_the_title() . '">' . get_the_title() . '</a></p>';
在 WordPress 中有不止一种方法可以做到这一点(几乎所有的事情),所以这取决于你在做什么以及代码中还有什么。还有 query_posts()
和 wp_get_recent_posts()
...真的太多了,不一一列举了。我会 post 更多链接,但我的代表不够高。
我会开始研究 WP_Query,因为您可以从中提取任何您想要的数据,并将其格式化为您满意的格式。
总之,希望对你有所帮助。
我想在 wordpress 中创建这样的东西,以便在 wordpress 页面中我可以向用户显示链接到他们的 post 链接的 post 标题以及那些 post秒。
我应该在 wordpress 中使用什么样的代码?
我是 wordpress 编码的新手。
所以请给我一些示例代码,以便我可以使用。
我还想从一个特殊类别中选择 posts。我该怎么做?
是否有任何 wordpress 插件可以做到这一点?
分页链接也很重要。
谢谢
我会调查 WP_Query。可能需要一些时间来习惯它,但它可以让您回显所有您想要的数据。我现在几乎什么都用它。
在 $args
数组中定义要查询的内容(例如来自特定类别的 posts,有多少,按什么顺序),然后从那里可以拉出标题、发布日期、附件、摘录、特色图片等。
<?php
// The Query
$args = array(
'numberposts' => '5',
'category_name' => 'my-category', // the slug
'offset' => '0',
'orderby' => 'post_date',
'order' => 'DESC',
'post_status' => 'publish'
);
$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
}
?>
WP_query 的重要之处在于,您可以使用它在 1 个模板上创建多个循环。这将取代模板中的正常循环。
对于日期,您可以使用 the_date() 或 get_the_date()
。所以你可以做一个
echo '<p><span class="date">' . get_the_date() . '</span> <a class="my-title" href="' . get_the_title() . '">' . get_the_title() . '</a></p>';
在 WordPress 中有不止一种方法可以做到这一点(几乎所有的事情),所以这取决于你在做什么以及代码中还有什么。还有 query_posts()
和 wp_get_recent_posts()
...真的太多了,不一一列举了。我会 post 更多链接,但我的代表不够高。
我会开始研究 WP_Query,因为您可以从中提取任何您想要的数据,并将其格式化为您满意的格式。
总之,希望对你有所帮助。