duanlu0075 2015-10-21 01:07
浏览 22

仅在wordpress元行副词cubell主题中显示顶级类别

I am using a theme with the code below to show the categories on the by-line. I was wondering if there is a way to show only the first category, not all of the categories that the post is associated with. My coding skill does not extend this far!

Thanks in advance for any help.

R. Sam

if ( ! function_exists( 'cb_byline' ) ) {
    function cb_byline( $cb_cat = true, $cb_post_id = NULL, $cb_short_comment_line = false, $cb_posts_on = false, $cb_post_views_off = false ) {

        if ( $cb_post_id == NULL ) {
            global $post;
            $cb_post_id = $post->ID;
        }

        $cb_meta_onoff = ot_get_option( 'cb_meta_onoff', 'on' );
        $cb_byline_author = ot_get_option( 'cb_byline_author', 'on' );
        $cb_byline_date = ot_get_option( 'cb_byline_date', 'on' );
        $cb_byline_category = ot_get_option( 'cb_byline_category', 'on' );
        $cb_byline_comments = ot_get_option( 'cb_byline_comments', 'on' );
        $cb_byline_postviews = ot_get_option( 'cb_byline_postviews', 'off' );
        $cb_disqus_code = ot_get_option( 'cb_disqus_shortname', NULL );
        $cb_byline = $cb_cat_output = $cb_comments = $cb_post_views = NULL;
        $cb_cats = get_the_category($cb_post_id);

        if (  ! empty ( $cb_cats ) && ( $cb_cat == true ) ) {
            $cb_cat_output = ' <div class="cb-category cb-byline-element"><i class="fa fa-folder-o"></i> ';
            $i = 1;
            foreach($cb_cats as $category) {
                if ( $i != 1 ) { $cb_cat_output .= ', '; }
                 $cb_cat_output .= ' <a href="' . get_category_parents( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", "cubell" ), $category->name ) ) . '">' . $category->cat_name.'</a>';
                 $i++;
            }
            $cb_cat_output .= '</div>';
        }
  • 写回答

1条回答 默认 最新

  • doucan1979 2015-10-21 03:52
    关注
    if ( ! function_exists( 'cb_byline' ) ) {
        function cb_byline( $cb_cat = true, $cb_post_id = NULL, $cb_short_comment_line = false, $cb_posts_on = false, $cb_post_views_off = false ) {
    
            if ( $cb_post_id == NULL ) {
                global $post;
                $cb_post_id = $post->ID;
            }
    
            $cb_meta_onoff = ot_get_option( 'cb_meta_onoff', 'on' );
            $cb_byline_author = ot_get_option( 'cb_byline_author', 'on' );
            $cb_byline_date = ot_get_option( 'cb_byline_date', 'on' );
            $cb_byline_category = ot_get_option( 'cb_byline_category', 'on' );
            $cb_byline_comments = ot_get_option( 'cb_byline_comments', 'on' );
            $cb_byline_postviews = ot_get_option( 'cb_byline_postviews', 'off' );
            $cb_disqus_code = ot_get_option( 'cb_disqus_shortname', NULL );
            $cb_byline = $cb_cat_output = $cb_comments = $cb_post_views = NULL;
            $cb_cats = get_the_category($cb_post_id);
    
            if (  ! empty ( $cb_cats ) && ( $cb_cat == true ) ) {
                $cb_cat_output = ' <div class="cb-category cb-byline-element"><i class="fa fa-folder-o"></i> ';
                $i = 1;
         //       foreach($cb_cats as $category) {
                    if ( $i != 1 ) { $cb_cat_output .= ', '; }
                     $cb_cat_output .= ' <a href="' . get_category_parents( $cb_cats[0]->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", "cubell" ), $cb_cats[0]->name ) ) . '">' . $cb_cats[0]->cat_name.'</a>';
                     $i++;
        //        }
                $cb_cat_output .= '</div>';
            }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?