傻大憨

分类: 建站知识

wordpress子分类调用父分类名称和链接

专为导航而生,在wordpress模板制作过程中常常会在做breadcrumbs导航时会用到,子分类调用父分类的名称和链接,下面这段简洁的代码,可以完美解决这个问题。

<?php echo get_category_parents( $cat, true, ' &raquo; ' ); ?>

下面这种方法也可以,不过代码不够简洁。

<?php
if ( is_category() ) {
    // Get the current category term id.
    $query_obj = get_queried_object();
    $term_id   = $query_obj->term_id;
 
    echo get_term_parents_list( $term_id, 'category' );
}
?>

第三种方法,调用分类目录名称和链接,作为导航。

<?php
if ( ( is_tax() || is_category() || is_tag() ) ) {
    $trail     = '';
    $home      = '/<a href="' . get_home_url() . '">Home</a>';
    $query_obj = get_queried_object();
    $term_id   = $query_obj->term_id;
    $taxonomy  = get_taxonomy( $query_obj->taxonomy );
 
    if ( $term_id && $taxonomy ) {
        // Add taxonomy label name to the trail.
       // $trail .=  '/' . $taxonomy->labels->menu_name;
        // Add term parents to the trail.
        $trail .= '/' . get_term_parents_list( $term_id, $taxonomy->name, array( 'inclusive' => false ) );
    }
 
    // Print trail and add current term name at the end.
    echo '<p class="breadcrumb-trail">' . $home . $trail . $query_obj->name . '</p>';
}
?>

wordpress按栏目别名调用最新内容

用wordpress制作网站模板时,可以使用以下代码,即可实现按栏目别名调用该栏目下的最新内容。

<?php $cmntCnt = 1;
$cat=get_category_by_slug('news'); 
?>
<?php $posts = get_posts( "category=$cat->term_id&numberposts=3" ); ?>
<?php if( $posts ) : ?>
<?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
<li>  
<h6 class="wow fadeInUp" data-wow-delay="0.2s"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php echo cut_str($post->post_title,38); ?></a></h6><span class="wow fadeInUp" data-wow-delay="0.4s"><?php the_category(', '); ?></span><span class="text-muted wow fadeInUp" data-wow-delay="0.4s"> - <?php the_time(get_option('date_format')) ?></span>
<p class="text-muted d-block mt-3 wow fadeInUp" data-wow-delay="0.6s"><?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 100, '…'); ?></p>
</li>

<?php endforeach; ?>
<?php endif; ?>
<?php wp_reset_query();?>

WordPress the_category与single_cat_title

在wordpress网站主题开发用常会用到调用分类目录的名称,the_category与single_cat_title都可以调用出分类目录的名称。

<?php single_cat_title(); ?>
<?php the_category(); ?>

但是,不少人搞不清楚二者有什么区别,其实很简单。

如果用single_cat_title调用分类名称,在分类里没文章时可以显示分类名称。用the_category分类名称,在分别里没文章时不会显示分类名称。

就这么点区别,其它的没什么区别。

WordPress调用当前文章作者头像

制作wordpress博客主题时经常会到用,需要调用wordpress当前文章作者头像的时候,用下面的这段代码即可。

<?php if (have_posts()) : the_post(); update_post_caches($posts); ?>
//wodepress.com
<?php echo get_avatar( get_the_author_email(), '80' );?>//80代表头像的大小
<?php endif; ?>

wordpress获取父页面的2种方法

wordpress模板制作的过程中有时会用到获取父页面的ID,下面是wordpress获取父页面的2种方法。

方法一

global $post;
$id = $post -> ID;
$parent = get_post_ancestors($post -> ID);
print_r($parent);

方法二

global $post;
$parent_id = $post -> post_parent;
echo $parent_id;

wordpress调用当前页面ID

在制作wordpress模板时常会用到的,wordpress调用当前页面ID代码。

<?php global $post;
$id = $post -> ID;
echo $id; ?>

在需要的位置上这段代码,即可显示出该页面的ID。

wordpress调用全站随机文章

wordpress调用全站随机文章代码

<?php

global $post;

$postid = $post->ID;

$args = array( ‘orderby’ => ‘rand’, ‘post__not_in’ => array($post->ID), ‘showposts’ => 10); // 显示篇数

$query_posts = new WP_Query();

$query_posts->query($args);

?>

<?php while ($query_posts->have_posts()) : $query_posts->the_post(); ?>

<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>

<?php endwhile; ?>

wordpress调用同分类随机文章

wordpress调用同分类随机文章代码

<?php

$cat = get_the_category();

foreach($cat as $key=>$category){

$catid = $category->term_id;}

$args = array('orderby' => 'rand','showposts' => 8,'cat' => $catid ); // 显示篇数

$query_posts = new WP_Query();

$query_posts->query($args);

while ($query_posts->have_posts()) : $query_posts->the_post();?>

<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>

<?php endwhile;?>

<?php wp_reset_query(); ?>

wordpress调用全站热门文章

wordpress调用全站热门文章代码

<?php

$post_num = 10; // 显示篇数

$args = array(

‘post_password’ => ”,

‘post_status’ => ‘publish’, // 只选公开的文章.

‘post__not_in’ => array($post->ID),//排除当前文章

‘caller_get_posts’ => 1, // 排除置顶文章.

‘orderby’ => ‘comment_count’, // 依评论数排序.

‘posts_per_page’ => $post_num

);

$query_posts = new WP_Query();

$query_posts->query($args);

while( $query_posts->have_posts() ) { $query_posts->the_post(); ?>

<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>

<?php } wp_reset_query();?>

WordPress调用指定分类文章

wordpress按分类ID调用指定分类的文章代码

<?php
    $args=array(
        'cat' => 1,   // 分类ID
        'posts_per_page' => 10, // 显示篇数

    );
    query_posts($args);

    if(have_posts()) : while (have_posts()) : the_post();
?>
    <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 
    </li>
<?php  endwhile; endif; wp_reset_query(); ?>

wordpress调用最新文章

wordpress调用最新文章的代码

<?php query_posts('showposts=6&cat=-1'); ?>  // 显示篇数和排除分类
<ul>  
<?php while (have_posts()) : the_post(); ?>  
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>  
<?php endwhile;?>  
</ul>  

河北专业的外贸网站建设与海外推广公司

燕子丹(yanzidan.com)是河北省一家专业的外贸网站建设与海外推广公司,专注于为企业提供一站式外贸网站建设和全球市场拓展服务。凭借15年的行业经验,燕子丹在外贸网站设计、SEO优化、Google推广等领域积累了丰富的实战经验,致力于帮助企业提升品牌知名度和市场份额。

核心服务与优势

1. 专业的外贸网站建设

燕子丹提供从网站策划、设计到开发的全方位服务,确保网站符合国际标准,具备良好的用户体验和多语言支持功能。公司采用自研SEO技术,结合谷歌优化策略,打造适合Google SEO的外贸网站。

2. 谷歌SEO优化

公司专注于通过关键词研究、内容优化、用户体验提升和外部链接建设等手段,确保网站在Google、Bing等主流搜索引擎上获得长期稳定的排名效果。燕子丹坚持使用白帽技术进行优化,避免搜索引擎惩罚,从而降低获客成本,提升转化率。

3. 多语言支持与国际化设计

针对不同国家和地区的市场需求,燕子丹提供多语言网站设计服务,支持目标市场的主流语言,并结合本地化关键词优化,确保网站内容与目标受众的文化和需求高度匹配。

4. 海外推广与数据分析

燕子丹不仅提供网站建设和优化服务,还通过社交媒体营销、内容营销和广告投放等多渠道推广手段,扩大品牌影响力。同时,公司利用数据分析工具,监测网站流量和用户行为,持续优化推广策略。

服务案例与客户反馈

燕子丹凭借其专业的技术团队和丰富的行业经验,已为众多企业提供了成功的外贸建站和推广服务。通过优化关键词布局、提升网站加载速度和优化用户体验,燕子丹帮助客户显著提升了网站流量和询盘量。

燕子丹作为河北地区领先的外贸建站和海外推广公司,凭借其专业的技术实力、丰富的行业经验和经济高效的建站方案,成为企业拓展全球市场的可靠选择。公司致力于通过谷歌SEO优化和多语言支持,助力企业提升国际竞争力,实现高效出海。

燕子丹官网

http://www.yanzidan.com