Questions tagged «posts»

帖子是WordPress的核心。它们存储内容,分类并可以通过meta进行扩展。帖子按帖子类型分组,并按分类在其帖子类型中分类(尽管一个分类法可以跨越多个帖子类型)。


5
确定页面是否为帖子页面
在“ 阅读设置”页面上,您可以设置“首页”和“帖子页面”。您可以检查当前页面是否is_front_page(); “帖子页面”有类似的功能吗?我注意到这is_page();不适用于此特殊页面。 谢谢
18 posts  pages 


5
如何标记每个第三条帖子
我正在为我的乐队在WordPress网站上工作,我想在博客页面上的每条第三条帖子上都标上一个特殊的类,有人对如何实现这一目标有任何指示吗?任何帮助都非常非常感谢,谢谢!摇滚乐。

6
在循环中打印当前帖子索引号
我正在WordPress上工作,这里有以下代码来获取循环内的帖子。 <?php $posts = $woo_options['woo_latest_entries']; query_posts('post_type=post&category_name=company'); if ( have_posts() ) : while ( have_posts() ) : the_post(); $count++; ?> /// Post Content Goes Here // <?php endwhile; endif; ?> 里面的哪个Output循环这样的内容... Post Goes Here .... Other Post Goes Here .... Another Post Goes Here .... ..... 我想要的是在循环中打印当前帖子索引号。例 1. Post Goes Here …
17 posts  loop 


1
将具有特色的内容按原始顺序保留在首页中
我正在搜索如何将精选帖子保留在我的博客主页中,而不将其从查询帖子中排除。我的博客使用二十四岁主题。我找到了这个解决方案。 从主题的inc文件夹中打开Featured-content.php,然后查找以下代码(在本例中为第269行)。 $query->set( 'post__not_in', $featured ); 只需在该行前面加上两个斜杠将其注释掉即可: // $query->set( 'post__not_in', $featured ); 但是该文件没有该行,并且子主题不能覆盖父主题的inc文件夹。 我找到了另一个解决方案,它可以工作,但是,问题是此代码显示的是精选内容发布,而不是按其原始顺序显示。当旧内容帖子(我正在使用粘性帖子制作特色帖子)成为精选帖子时,精选内容帖子将成为第一顺序,然后成为其他帖子。 我尝试使用这样的条件标签。 function show_featured_content_on_home() { if ( !is_home() ) { remove_action( 'pre_get_posts', array( 'Featured_Content', 'pre_get_posts' ) ); } } add_action( 'init', 'show_featured_content_on_home', 31 ); 第二页,依此类推-依次显示精选帖子-但首页仍然存在问题。 有什么建议么?

3
在永久链接后添加其他参数?
如何在固定链接后添加额外的参数,特别是在使用自定义帖子类型的情况下? 例如,假设http://mysite/album/record-name是永久链接。如何http://mysite/album/record-name/related不打开404或重定向? 如果该帖子不存在,WordPress似乎不会调用该帖子模板。

1
将自定义帖子类型限制为仅网站管理员角色
如何从非管理员用户的仪表板中删除此自定义帖子类型? /* Add Websites Custom Post Type */ add_action( 'init', 'create_website_type' ); function create_website_type() { register_post_type( 'website', array( 'labels' => array( 'name' => __( 'Websites' ), 'singular_name' => __( 'Website' ), 'add_new' => __( 'Add New Website' ), 'add_new_item' => __( 'Add New Website' ), 'edit' => __( 'Edit Website' …

2
WP_Query分页on single-custom.php
我要做什么: WP_Query在single-custom-post-type.php模板文件中设置分页 我做了什么 1)创建了一个称为“作者”的帖子类型。该帖子类型中的每个帖子都是一位作者。 2)标准编辑帖子屏幕页面包含一个下拉列表,其中列出了作者自定义帖子类型的所有帖子(作者)。 3)创建了single-authors.php模板,该模板使用下拉菜单中的作者元数据查询所有帖子,因此结果是分配了相同作者(类似于存档)的帖子列表: <?php // set the "paged" parameter (use 'page' if the query is on a static front page) global $paged; /*We need this here to add and maintain Pagination if Template is assigned to Front Page*/ if ( get_query_var( 'paged' ) ) { $paged = …


4
保存/更新后如何添加管理员通知
我有一个帖子类型,使用post_save从帖子元中获取地址并从Google API中检索经/纬度坐标。我需要一种通知用户检索协调项是否存在问题的方法。我尝试使用admin_notices,但未显示任何内容: public static function update_notice() { echo "<div class='error'><p>Failed to retrieve coordinates. Please check key and address.<p></div>"; remove_action('admin_notices', 'update_notice'); } add_action('admin_notices', array('GeoPost', 'update_notice')); 我不确定是否使用不正确或使用错误的上下文。需要明确的是,在实际代码中,add_action位于同一类的另一个函数中。很好


3
如何用句子而不是单词来结束摘录?
这是我主页上帖子的摘录。我想用一句话结束摘录。在这种情况下,这就是机会。'。我知道如何修改长度,但是不会做我想要的。 这是其他网站的摘录。在这里,您会看到摘录以一个适当的句子结尾,而上面的句子以下一个句子的“主动”结尾。 通用汽车实施解决方案后:

4
获取当前页码
每页有20条帖子的情况。我想获取当前页码,以便在底部进行一些漂亮的页面链接。您如何获得当前页面。我试过了 <?php echo '(Page '.$page.' of '.$numpages.')'; ?> 它仅在每页上显示第1页,共1页。 有任何想法吗, 奇妙
15 posts  pages 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.