word press常用的标签调用
1、头部导航自定义调用-------------------------------------------------------------------------------------------------------------------
<nav>
<ul>
<?php
// 获取WordPress中的主菜单
$main_menu_items = wp_get_nav_menu_items('main-menu');
// 循环遍历每个菜单项
foreach ($main_menu_items as $item) {
// 输出菜单项
echo '<li><a href="' . $item->url . '">' . $item->title . '</a>';
// 检查是否存在子菜单项
$sub_menu_items = wp_get_nav_menu_items($item->ID);
if ($sub_menu_items) {
echo '<ul>';
// 循环遍历子菜单项
foreach ($sub_menu_items as $sub_item) {
// 输出子菜单项
echo '<li><a href="' . $sub_item->url . '">' . $sub_item->title . '</a></li>';
}
echo '</ul>';
}
echo '</li>';
}
?>
</ul>
</nav>
1-1、头部导航自定义调用-------------------------------------------------------------------------------------------------------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
2、轮播图调用-------------------------------------------------------------------------------------------------------------------
<?php get_header(); ?>
<div id="frame-top-slider-detail"> </div>
<div id="frame-top-slider" class="smallslider">
<!-- 大图轮播-->
<script type="text/javascript">
$(document).ready(function () {
var l=$('#bigpic').children().length;
var str='';
for(var i=0; i < l;i++)
{
if(i==0)
str += '<li class="on" ></li>';
else
str += '<li class=" "></li>';
}
$('#pager').html(str);
var mosaic = XMosaic('bigpic', { pager: 'pager', delay: 10000, countX: 10, countY: 5, how: 9, order: 0 });
});
</script>
<div id ="bigpic">
<a style="left: 0px; top: 0px; position: absolute;" target="_blank" href="/13v0to-1.html">
<img src='<?php echo get_option(' wpd_banner1 '); ? alt="wordpress如何进行仿站" >' alt='1' />
</a><a style="left: 0px; top: 0px; position: absolute;" target="_blank" href="">
<img src='<?php echo get_option(' wpd_banner2 '); ? alt="wordpress如何进行仿站" >' alt='2' />
</a> </div>
</div>
</div>
3、部分文章图调用-------------------------------------------------------------------------------------------------------------------
div id="frame-top-slider-mask">
<ul class="ctrls" id="pager">
</ul>
</div>
</div>
<div id="frame-main-body">
<div id="frame-main-wrapper" class="yui3-g">
<div id="frame-main" class="yui3-u">
<div id="frame-main-left" class="yui3-u-1-2">
<div class="module module_left">
<div class="module-name">
<a href="/75d14e-1.html" target="_blank">学院新闻</a>
<a style="font-size:13px; margin-left:250px; color:blue;" target="_blank" href="/75d14e-1.html">更多</a>
</div>
<div class="module-spliter">
<div> </div>
</div>
<div class="module-warpper">
<div>
<div class="row pd5 fb">
<a target="_blank" title="海洋与环境学院孙军院长一行走访国家海洋信息中心" href="/lqpmfv.html">海洋与环境学院孙军院长一行走访国家海洋信息中心</a>
</div>
<li class="row spic tag_description">
<a target="_blank" href="/lqpmfv.html" title="海洋与环境学院孙军院长一行走访国家海洋信息中心">
<img width=360 style="max-width:90%" align="left" alt="海洋与环境学院孙军院长一行走访国家海洋信息中心" src="<?php bloginfo('template_url'); ?>/picture/540_225.jpg">
</a>
</li>
<div style="clear:both;"></div>
</div> <table cellspacing="0" cellpadding="0" class="tag_table">
<tbody>
<?php
query_posts(
//'query_type = post&posts_per_page=8'
array ( 'category_name' => 'business', 'posts_per_page' => 8 )
);
$i=0; while(have_posts()) : the_post(); $i++; ?>
<tr>
<td width="100%">
<ul>
<li class="tag_title">
<a target="_blank" title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
</ul>
</td>
</tr>
<?php endwhile; wp_reset_query(); ?>
</tbody>
</table> </div>
</div>
</div>
<div id="frame-main-right" class="yui3-u-1-2">
<div class="module">
<div class="module-name"> <a href="/c6c7e7-1.html" target="_blank">通知公告</a>
<a style="font-size:13px; margin-left:250px; color:blue;" target="_blank" href="/c6c7e7-1.html">更多</a>
</div>
<div class="module-spliter">
<div> </div>
</div>
<div class="module-warpper">
<table cellspacing="0" cellpadding="0" class="tag_table">
<tbody>
<?php
query_posts(
//'query_type = post&posts_per_page=8'
array ( 'category_name' => 'technolo', 'posts_per_page' => 8 )
);
$i=0; while(have_posts()) : the_post(); $i++; ?>
<tr>
<td width="100%">
<ul>
<li class="tag_title">
<a target="_blank" title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_time('Y年n月j日'); ?> <?php the_title(); ?></a>
</li>
</ul>
</td>
</tr>
<?php endwhile; wp_reset_query(); ?>
</tbody>
</table> </div>
</div>
</div>
</div>
<div id="frame-side" class="yui3-u">
<div id="placehoder"></div>
<ul>
<li><a target="" href="/906368.html">研究成果</a></li><li><a target="" href="/faef50-1.html">学术交流</a></li><li><a target="_blank" href="http://hyxy.tust.edu.cn/shiyanshifan/1shoye.html">实践教学</a></li><li><a target="" href="/ccac59.html">教学成果</a></li><li><a target="" href="/4d3baa-1.html">学生资助</a></li><li><a target="" href="/801d37-1.html">校友相聚</a></li><li><a target="" href="#">学术报告</a></li> </ul>
</div>
</div>
<div id="frame-main-link" class="yui3-g">
<div>
<div id="demo" style="overflow:hidden;height:110px;margin:0 auto;">
<table align="left" cellpadding="0" cellspace="0" border="0">
<tr>
<td id="demo1" valign="top">
<div>
<a style="width:0px;" href="/0c8a9f.html#ppzy" target="_blank"><img src="<?php bloginfo('template_url'); ? alt="wordpress如何进行仿站" >/picture/57243dbb36ec49fe8ea8839a947fe310.jpg" /></a><img src="<?php bloginfo('template_url'); ? alt="wordpress如何进行仿站" >/picture/869b86dfeae34a31b851fb01cec2b074.jpg" /><a style="max-width:90%" href="http://hyhjbhjs.cl1.soochong.com" target="_blank"><img src="<?php bloginfo('template_url'); ? alt="wordpress如何进行仿站" >/picture/2015-08-27-20-0606158108.jpg" /></a><img src="<?php bloginfo('template_url'); ? alt="wordpress如何进行仿站" >/picture/39bfa2a5c9be4d87bb8c50a886d3f3c0.jpg" /></div>
</td>
<td id="demo2" valign="top"> </td>
</tr>
</table>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
3、文章分类页面模板标签调用-------------------------------------------------------------------------------------------------------------------
方法一:
<?php
if (have_posts()) {
while (have_posts()) {
the_post();
?>
<a href="<?php echo esc_url(get_permalink(get_the_ID())); ?>" class="gonew_item curnew" data-id="">
<div class="imgbox">
<img src="<?php the_field('litpic'); ?>" alt="<?php the_title(); ?> ">
</div>
<div class="ctext">
<div class="t01 dot"><?php the_title(); ?> </div>
<div class="t02 dot">V1Pro</div>
<div class="t03 dot">Innovation Meets Limitless Potential</div>
<div class="t04"></div>
</div>
<div class="ctit">Flash</div>
<div class="cnew">New</div>
</a>
<?php
}
} else {
echo ' <a class="gonew_item curnew" data-id="">没有找到相关文章</a>';
}
?>
方法二:
<?php if(have_posts()) { ?>
<?php while(have_posts()) { ?>
<?php the_post(); ?>
<a href="<?php echo esc_url(get_permalink(get_the_ID())); ?>" class="gonew_item curnew" data-id="">
<div class="imgbox">
<img src="<?php the_field('litpic'); ?>" alt="<?php the_title(); ?> ">
</div>
<div class="ctext">
<div class="t01 dot"><?php the_title(); ?> </div>
<div class="t02 dot">V1Pro</div>
<div class="t03 dot">Innovation Meets Limitless Potential</div>
<div class="t04"></div>
</div>
<div class="ctit">Flash</div>
<div class="cnew">New</div>
</a>
<?php } // end while ?>
<?php } // end if ?>
4、获取所有产品分类页面模板标签调用-------------------------------------------------------------------------------------------------------------------
<?php
// WP_Query 获取产品
$args = array(
'post_type' => 'product',
'posts_per_page' =>10, // 显示所有产品,可以设置为想要显示的数量
);
$products = new WP_Query($args);
if ($products->have_posts()) :
while ($products->have_posts()) : $products->the_post();
?>
<div class="item">
<a href="<?php the_permalink(); ?>">
<div class="imgbox"><img src="<?php the_post_thumbnail('medium'); ?>" alt="<?php the_title(); ?> "></div>
<div class="t"><?php the_title(); ?> </div>
<span>Learn More</span>
</a>
</div>
<?php
endwhile;
wp_reset_postdata(); // 重置查询
else :
echo ' <div class="gonew_item curnew" style="width: 100%;text-align: center;">没有找到相关文章</div>';
endif;
?>
4-2、获取当前产品分类页面模板标签调用-------------------------------------------------------------------------------------------------------------------
5、搜索标签标签调用-------------------------------------------------------------------------------------------------------------------
(1)这个代码可以放到任何位置调用
<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label>
<span class="screen-reader-text"><?php echo _x( 'Search for:', 'label' ); ?></span>
<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search …', 'placeholder' ); ?>" value="<?php echo get_search_query(); ?>" name="s" />
</label>
<button type="submit" class="search-submit"><?php echo esc_html_x( 'Search', 'submit button' ); ?></button>
</form>
(2)搜索结果一般是search.php这个页面
<main id="main" class="site-main" role="main">
<header class="page-header">
<h1 class="page-title"><?php printf( esc_html__( 'Search Results for: %s', 'your-theme-text-domain' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
</header>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
</header><!-- .entry-header -->
<div class="entry-content">
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
</article><!-- #post-<?php the_ID(); ?> -->
<?php endwhile; ?>
<?php the_posts_navigation(); ?> <!-- 分页导航 -->
<?php else : ?>
<p><?php esc_html_e( 'No results found.', 'your-theme-text-domain' ); ?></p>
<?php endif; ?>
</main><!-- #main -->
5、上下页调用-------------------------------------------------------------------------------------------------------------------
5.1、总分类文章上下页
<a href="<?php echo get_permalink(get_previous_post()->ID); ?>" title="<?php echo get_the_title(get_previous_post()->ID); ?>">
<div>
<img src="<?php echo get_theme_file_uri( 'static/images/x_left_h.png' ); ?>">
</div>
<div>
<span>上一篇</span><span><?php echo get_the_title(get_previous_post()->ID); ?></span>
</div>
</a>
<a href="<?php echo get_permalink(get_next_post()->ID); ?>" title="<?php echo get_the_title(get_next_post()->ID); ?>">
<div>
<span>下一篇</span><span><?php echo get_the_title(get_next_post()->ID); ?></span>
</div>
<div>
<img src="<?php echo get_theme_file_uri( 'static/images/x_right_h.png' ); ?>">
</div>
</a>
5.1、单曲分类文章上下页 比如文章子分类是live-streaming
<?php
// 获取当前文章的分类
$categories = get_the_category();
$category_slugs = array();
foreach ($categories as $category) {
$category_slugs[] = $category->slug;
}
// 检查当前文章是否属于"Live streaming"分类或其子分类
if (in_category('live-streaming') || cat_is_ancestor_of(get_cat_ID('live-streaming'), $categories[0])) {
// 获取上一篇文章的链接和标题
$previous_post = get_previous_post(true);
if (!empty($previous_post)) {
echo '<a href="' . get_permalink($previous_post->ID) . '" title="' . get_the_title($previous_post->ID) . '">';
echo '<div><img src="' . get_theme_file_uri('static/images/x_left_h.png') . '"></div>';
echo '<div><span>上一篇</span><span>' . get_the_title($previous_post->ID) . '</span></div>';
echo '</a>';
}else{
echo '<a >';
echo '<div><img src="' . get_theme_file_uri('static/images/x_left_h.png') . '"></div>';
echo '<div><span>上一篇</span><span>没有了。!</span></div>';
echo '</a>';
}
// 获取下一篇文章的链接和标题
$next_post = get_next_post(true);
if (!empty($next_post)) {
echo '<a href="' . get_permalink($next_post->ID) . '" title="' . get_the_title($next_post->ID) . '">';
echo '<div><span>下一篇</span><span>' . get_the_title($next_post->ID) . '</span></div>';
echo '<div><img src="' . get_theme_file_uri('static/images/x_right_h.png') . '"></div>';
echo '</a>';
}else{
echo '<a>';
echo '<div><span>下一篇</span><span> 没有了。</span></div>';
echo '<div><img src="' . get_theme_file_uri('static/images/x_right_h.png') . '"></div>';
echo '</a>';
}
}
?>
5.3、 WooCommerce产品分类上下页
<a href="<?php echo get_permalink(get_previous_post()->ID); ?>" title="<?php echo get_the_title(get_previous_post()->ID); ?>">
<div>
<img src="<?php echo get_theme_file_uri( 'static/images/x_left_h.png' ); ?>">
</div>
<div>
<span>上一篇</span><span><?php echo get_the_title(get_previous_post()->ID); ?></span>
</div>
</a>
<a href="<?php echo get_permalink(get_next_post()->ID); ?>" title="<?php echo get_the_title(get_next_post()->ID); ?>">
<div>
<span>下一篇</span><span><?php echo get_the_title(get_next_post()->ID); ?></span>
</div>
<div>
<img src="<?php echo get_theme_file_uri( 'static/images/x_right_h.png' ); ?>">
</div>
</a>
5.4、 WooCommerce 中的某个产品分类文章上下页
<?php
// 检查当前文章是否属于 WooCommerce 中的 "Custom Signs" 产品分类或其子分类
if (has_term('custom-signs', 'product_cat')) {
// 获取上一篇文章的链接和标题
$previous_post = get_previous_post(true);
if (!empty($previous_post)) {
echo '<a href="' . get_permalink($previous_post->ID) . '" title="' . get_the_title($previous_post->ID) . '">';
echo '<div><img src="' . get_theme_file_uri('static/images/x_left_h.png') . '"></div>';
echo '<div><span>上一篇</span><span>' . get_the_title($previous_post->ID) . '</span></div>';
echo '</a>';
}
// 获取下一篇文章的链接和标题
$next_post = get_next_post(true);
if (!empty($next_post)) {
echo '<a href="' . get_permalink($next_post->ID) . '" title="' . get_the_title($next_post->ID) . '">';
echo '<div><span>下一篇</span><span>' . get_the_title($next_post->ID) . '</span></div>';
echo '<div><img src="' . get_theme_file_uri('static/images/x_right_h.png') . '"></div>';
echo '</a>';
}
}
?>