post_object 文章对象
Repeater 复制
必须要用的变量 ‘option’
<?php echo the_field('字段名','option');?> <?php the_field('字段名','option');?> <?php if( have_rows('字段名','option') ):?> <?php while ( have_rows('同上字段名','option') ) : the_row();?> <li class="active"><span><?php the_sub_field('内字段名');?></span></li> <?php endwhile; ?> <?php else : endif; ?>
<?php if( have_rows('字段名') ):?> <?php while ( have_rows('同上字段名') ) : the_row();?> <li class="active"><span><?php the_sub_field('内字段名');?></span></li> <?php endwhile; ?> <?php else : endif; ?>
<?php if( have_rows('字段') ): ?> <ul class="slides"> <?php while( have_rows('同上字段') ): the_row(); ?> <li class="slide"> <?php if( get_row_layout() == '样式' ): $image = get_sub_field('内字段名'); ?> <?php the_sub_field('内字段标签');?> <?php endif; ?> </li> <?php endwhile; ?> </ul> <?php endif; ?>
<?php echo the_field('jiudian-jiage');?> <?php the_field('jiudian-jiage');?>
<?php $tablepress_id = get_field( 'biaoge' ); echo do_shortcode( '[table id="'.$tablepress_id.'" /]' ); ?>
<?php the_field(‘chengshi-link’, ‘option’); ?>
<?php global $post; $djiage = get_field('jiudian-jiage',$post->ID,false);?> <?php echo $djiage ?>
<?php $post_object = get_field('guanlianxiangmu'); if( $post_object ): // override $post $post = $post_object; setup_postdata( $post ); ?> <div> <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> <span>Post Object Custom Field: <?php the_field('field_name'); ?></span> </div> <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?> <?php endif; ?> <?php $post_objects = get_field('post_objects'); if( $post_objects ): ?> <ul> <?php foreach( $post_objects as $post): // variable must be called $post (IMPORTANT) ?> <?php setup_postdata($post); ?> <li> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <span>Post Object Custom Field: <?php the_field('field_name'); ?></span> </li> <?php endforeach; ?> </ul> <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?> <?php endif; $post_objects = get_field('post_objects'); if( $post_objects ): ?> <ul> <?php foreach( $post_objects as $post_object): ?> <li> <a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_title($post_object->ID); ?></a> <span>Post Object Custom Field: <?php the_field('field_name', $post_object->ID); ?></span> </li> <?php endforeach; ?> </ul> <?php endif;?> 相册
<?php $images = get_field('gallery'); if( $images ): ?> <ul> <?php foreach( $images as $image ): ?> <li> <a href="<?php echo $image['url']; ?>"> <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" /> </a> <p><?php echo $image['caption']; ?></p> </li> <?php endforeach; ?> </ul> <?php endif; ?>
<?php $images = get_field('gallery'); if( $images ): ?> <div id="slider" class="flexslider"> <ul class="slides"> <?php foreach( $images as $image ): ?> <li> <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /> <p><?php echo $image['caption']; ?></p> </li> <?php endforeach; ?> </ul> </div> <div id="carousel" class="flexslider"> <ul class="slides"> <?php foreach( $images as $image ): ?> <li> <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" /> </li> <?php endforeach; ?> </ul> </div> <?php endif; ?>
参考地址:https://www.advancedcustomfields.com/resources/gallery/
<?php wp_footer();?> <?php wp_head();?>
<?php bloginfo(‘template_url’); ?>
<?php wp_list_categories(‘hide_empty=0&child_of=32&exclude=&title_li=’); ?>
<?php if(has_post_thumbnail()){the_post_thumbnail(array(180,130));}else{echo '<img class="small_img" src="" style="opacity: 1.1; background: rgb(255, 255, 255) none repeat scroll 0% 0%;">';}?> the_post_thumbnail();// 没有输入参数,默认是 -> 'post-thumbnail' the_post_thumbnail('thumbnail');// Thumbnail (默认最大是 150px x 150px) the_post_thumbnail('medium');// Medium resolution (默认最大是 300px x 300px) the_post_thumbnail('large');// Large resolution (默认最大是 640px x 640px) the_post_thumbnail('full');// Full resolution (原始上传图片的大小) the_post_thumbnail( array(100,100));// 其他尺寸
<?php $catlink=get_category_link(12); echo $catlink ?>
<?php $cat= single_cat_title('', false); $catid = get_cat_ID($cat); if($catid == 14){$catid = 10;}; wp_list_categories('hide_empty=0&child_of='.$catid.'&exclude=&title_li='); ?>
<?php query_posts('showposts=6&cat=6'); while(have_posts()) : the_post(); ?> <?php endwhile; ?>
我们在制作wordpress主题的时候喜欢在调取中文分类名的时候也想自动显示这个分类名的英文名,比如说企业新闻这块,我们想显示出news的别名出来,那么在wordpress主题中,实现这个功能还是十分简单的,那么大家就仔细看教程咯! category函数 通常我们在调取分类的名称和链接的时候是直接使用
<?php the_category(); ?>
但是从中带来的问题是,不能只获取分类的名称,必须是分类的名称和链接的,那么我们这个时候就需要用到
<?php single_cat_title(); ?>
<?php foreach((get_the_category()) as ) { echo ->cat_name; ?>}
<?php = get_the_category(); echo [0]->cat_name; ?>
<?php = get_category(); echo ->name;?>
说到现在,我们都是在获取分类名,回归到重点,下面说下分类别名的获取方法是:
if(is_category()) { = get_query_var('cat'); = get_category(); echo "该分类别名为" . ->slug; }
<?php = get_category();echo ->slug;?>
<?php if(is_category()) { = get_query_var(‘cat’); = get_category();echo “” . ->slug; ?> }
<?php if( is_page() ){ = . get_option(‘display_copyright_text’); = get_post(->ID, ARRAY_A); echo = [‘post_name’]; ?> }
<?php bloginfo('name'); ?> : 名称(Title) <?php bloginfo('stylesheet_url'); ?> : CSS 文件路径 <?php bloginfo('pingback_url'); ?> : PingBack Url <?php bloginfo('template_url'); ?> : 模板文件路径 <?php bloginfo('version'); ?> : WordPress 版本 <?php bloginfo('atom_url'); ?> : Atom Url <?php bloginfo('rss2_url'); ?> : RSS 2.o Url <?php bloginfo('url'); ?> : Url <?php bloginfo('html_type'); ?> : 网页Html 类型 <?php bloginfo('charset'); ?> : 网页编码 <?php bloginfo('description'); ?> : 描述 <?php wp_title(); ?> : 特定内容页(Post/Page)的标题
//定义模板文件所在目录为 single 文件夹 define(SINGLE_PATH, TEMPLATEPATH . '/single'); //自动选择模板的函数 function single_template($single) { global $wp_query, $post; //通过分类别名或ID选择模板文件 foreach((array)get_the_category() as $cat) : if(file_exists(SINGLE_PATH . '/single-cat-' . $cat->slug . '.php')) return SINGLE_PATH . '/single-cat-' . $cat->slug . '.php'; elseif(file_exists(SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php')) return SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php'; endforeach; } //通过 single_template 钩子挂载函数 add_filter('single_template', 'single_template');
<?php $banquan_yiwen = get_post_meta($post->ID, 'banquan_yiwen', true); // 检查这个字段是否有值 if (empty ( $banquan_yiwen )) { $banquan_yiwen = ''; } else { echo '<span>译文申明: '. $banquan_yiwen .'</span>'; } ?>