空大

常用php标签调用[WordPress]

  1. <?php get_header(); ?>

    头部调用

  2. <?php get_footer(); ?>

    底部调用

  3. <?php get_footer(); ?>

    侧边栏调用

  4. <link href="<?php bloginfo('template_url'); ?>/sy/css.css" type="text/css">

    css路径,图片路径和js路径通用

  5. <a href="<?php the_permalink(); ?>">

    文章详情跳转

  6. <img src="<?php echo catch_that_image() ?>" alt="<?php the_title(); ?>">

    调用图片标签

  7. <?php the_title(); ?>

    文章标题

  8. <?php the_tags(''); ?>

    标签调用

  9. <?php echo mb_strimwidth(strip_tags(apply_filters(‘the_content’, $post->post_content)), 0, 60, ‘……’); ?>

    文章内容调用并限制字符

  10. <?php echo date(“Y-m-d”);?> <?php echo date(“Y-m-d H-i”);?>

    时间标签

  11. <?php if (have_posts()):while(have_posts()) :the_post(); ?><?php the_content(); ?><?php endwhile; ?><?php endif; ?>

    文章内容

  12. <?php bloginfo(‘name’); ?>

    网站域名

  13. <?php single_tag_title(); ?>

    tag标题

  14. <?php single_cat_title(); ?>

    分类页标题

 

index首页循环

调用id为1的文章 开始

<?php $the_query = new Wp_Query(array( cat => 1, orderby => id’, order => DESC’, posts_per_page => 4, paged => get_query_var(‘paged’, 1) )); ?> <?php if ($the_query->have_posts()) : ?> <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>

主体内容

 

<?php endwhile; ?> <?php wp_reset_postdata(); ?> <?php endif; ?>

调用id为1的文章 结束

 

栏目分类调用

<?php $terms = get_terms(‘category’, orderby=name&hide_empty=0’); $count = count($terms); if ($count > 0) { foreach ($terms as $key => $term) { if ($key <= 4) { echo ‘<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-84"><a class="elementor-item" href="' . get_term_link($term, $term->slug) . '" >‘ . $term->name . ‘</a></li>‘; } } } ?>

 

搜索页

循环查询规则

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

开始

 

//循环主体

<?php endwhile; ?><?php endif; ?>

结束

 

搜索框:

<form id="search_form" method="get" target="_search" action="<?php bloginfo('url'); ?>/" accept-charset="utf-8"> <input type="hidden" name="type" value="blog"> <input id="keyword" type="text" name="s" class="logoRDownC_input" value="<?php the_search_query(); ?>" placeholder="请输入搜索关键词"> <input type="submit" class="logoRDownC_input2" value="搜索"> </form>

 

function.php 页面自定义函数限制标题字符

<?phpfunction excerpttitle($max_length) { $title_str = get_the_title(); if(mb_strlen($title_str,’utf-8’) > $max_length) { $title_str = mb_substr($title_str,0,$max_length,’utf-8’).’…’; } return $title_str;}?>

调用方法:

<a href="<?php the_permalink(); ?>"><?php echo excerpttitle(8); ?> </a>

 

tag标签调用

<?php if (isset($_GET['showall'])) : $args = array('hide_empty' => 0); else : $page = (get_query_var('paged')) ? get_query_var('paged') : 1; $per_page = 80; $offset = ($page - 1) * $per_page; $args = array('number' => $per_page, 'offset' => $offset, 'hide_empty' => 0); endif; $taxonomy = 'post_tag'; $tax_terms = get_terms($taxonomy, $args); echo ''; foreach ($tax_terms as $tax_term) { echo '' . '</p> <li style="float:left"><a style="color:#fff;" href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __("View all posts in %s"), $tax_term->name ) . '" ' . '>' . $tax_term->name . '</a>&nbsp;&nbsp;&nbsp;</li> <p>'; } echo ''; ?lt;

 

分类页循环

$the_query = new Wp_Query(array(
'cat' => $cat,
'orderby' => 'id',
'order' => 'DESC',
'paged' => get_query_var('paged', 1)
)); ?>
<?php if ($the_query->have_posts()) : ?>
<?php while ($the_query->have_posts()) : $the_query->the_post();

主体内容

<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>

赞(0)
未经允许不得转载:剧搜博客 » 常用php标签调用[WordPress]

评论 抢沙发

9 + 7 =

登录

注册