wordpress调用相同文章形式的内容列表
文章目录
由
Deepseek提供支持
广告
大挖的wordpress导航主题,集成了两种文章形式,默认形式即导航形式,还有一个日志形式,就是我们传统说的资讯形式,在使用相关文章和资讯列表调用时,大挖使用的相关的wordpress文章形式调用,这样可以避免出样在不同的列表里出来导航列表内容又出现资讯文章内容。
现在把代码分享给大家,需要提示给大家的是此段代码里的post-format-image是主要的核心要素,格式是这样的post-format-{name},name是指文章形式的名称,可以用的有:aside、image、video、quote、link、gallery、status、audio、chat等wordpress默认的文章形式。
<?php $posts = get_posts(array( 'numberposts' => '10', 'post_type' => 'post', 'tax_query'=>array( array( 'taxonomy'=>'post_format', 'field' => 'slug', 'terms' => array('post-format-image') ) ), ) ); if($posts): foreach($posts as $post): ?> <li><a href="<?php the_permalink(); ?>" target="_blank" title="<?php the_title();?>"><?php the_title();?></a></li> <?php wp_reset_postdata(); endforeach; endif; ?>
内容页面调用相同文章形式的文章列表
<?php $posts = get_posts(array( 'numberposts' => '10', 'post_type' => 'post', 'exclude'=>get_the_ID(), 'tax_query'=>array( array( 'taxonomy'=>'post_format', 'field' => 'slug', 'terms' => array('post-format-image'.get_post_format()) ) ), ) ); if($posts): foreach($posts as $post): ?> <li><a href="<?php the_permalink(); ?>" target="_blank" title="<?php the_title();?>"><?php the_title();?></a></li> <?php wp_reset_postdata(); endforeach; endif; ?>
温馨提示 : 非特殊注明,否则均为©李联华的博客网原创文章,本站文章未经授权禁止任何形式转载;来自:俄亥俄州·哥伦布 ,欢迎您的访问!
文章链接:https://www.lilianhua.com/wordpress-calls-the-content-list-in-the-same-article-form.html
文章链接:https://www.lilianhua.com/wordpress-calls-the-content-list-in-the-same-article-form.html
English (US)
Español (ES)
Português (PT)
Français (CA)
Español (MX)
Español (VE)
Español (CO)
Español (AR)
Português (BR)
Quechua (PE)
Guaraní (PY)
简体中文 (ZH)
繁體中文 (HK)
日本語 (JP)
한국어 (KR)
हिन्दी (HI)
Pilipino (PH)
ไทย (TH)
Tiếng Việt (VN)
Bahasa Melayu (MY)
Bahasa Indonesia (ID)
বাংলা (BD)
اردو (PK)
සිංහල (LK)
ភាសាខ្មែរ (KH)
English (UK)
Français (FR)
Deutsch (DE)
Italiano (IT)
Русский (RU)
Nederlands (NL)
Türkçe (TR)
Polski (PL)
Svenska (SE)
Norsk (NO)
Dansk (DK)
Suomi (FI)
Ελληνικά (GR)
Čeština (CZ)
Magyar (HU)
Română (RO)
Български (BG)
Српски (RS)
Українська (UA)

