当前位置: 首页>>代码示例>>PHP>>正文


PHP get_the_category函数代码示例

本文整理汇总了PHP中get_the_category函数的典型用法代码示例。如果您正苦于以下问题:PHP get_the_category函数的具体用法?PHP get_the_category怎么用?PHP get_the_category使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_the_category函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: inti_get_categories_meta

 function inti_get_categories_meta($args = '')
 {
     $count = 0;
     $categories_list = '';
     $categories = get_the_category();
     foreach ($categories as $category) {
         $count++;
         if ($args['show_uncategorized']) {
             $categories_list .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__('View all posts in %s', 'inti'), $category->name) . '"><span class="label category">' . $category->name . '</span></a>';
             if ($count != count($categories)) {
                 $categories_list .= ' ';
                 //separator
             }
         } else {
             if ($category->slug != 'uncategorized' || $category->name != 'Uncategorized') {
                 $categories_list .= '<a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__('View all posts in %s', 'inti'), $category->name) . '"><span class="label category">' . $category->name . '</span></a>';
                 if ($count != count($categories)) {
                     $categories_list .= ' ';
                     //separator
                 }
             }
         }
     }
     return $categories_list;
 }
开发者ID:waqastudios,项目名称:inti-foundation,代码行数:25,代码来源:post-meta.php

示例2: bootstrap_breadcrumbs

/**
 * Add breadcrumbs functionality to your WordPress theme
 *
 * Once you have included the function in your functions.php file
 * you can then place the following anywhere in your theme templates
 * if(function_exists('bootstrap_breadcrumbs')) bootstrap_breadcrumbs();
 *
 * credit to: c.bavota - http://bavotasan.com (thanks for the code start)
 */
function bootstrap_breadcrumbs()
{
    echo '<ol class="breadcrumb">';
    echo '<li><a href="' . home_url('/') . '">Home</a></li>';
    // are we at "blog home"?
    if (is_home()) {
        echo '<li><a href="#">Blogs</a></li>';
    }
    // where else do we want breadcrumbs
    if (!is_page_template('pt-home.php') && !is_home()) {
        // check if we're in a commerce plugin
        if (function_exists('is_woocommerce') && is_woocommerce()) {
            echo '<li><a href="/publications/order/">Shop</a></li>';
            $product_cats = wp_get_post_terms(get_the_ID(), 'product_cat');
            echo '<li><a href="/publications/order/' . str_replace(" ", "-", $product_cats[0]->name) . '">' . $product_cats[0]->name . '</a></li>';
        }
        // breadcrumb wordpress structures
        if (is_category() || is_single() || is_single('aof')) {
            if (get_the_category()) {
                $category = get_the_category();
                echo '<li><a href="/blog/category/' . str_replace(" ", "-", $category[0]->cat_name) . '">' . $category[0]->cat_name . '</a></li>';
            }
            if (is_single()) {
                echo '<li class="active">';
                the_title();
                echo '</li>';
            }
        } elseif (is_page()) {
            echo '<li class="active">';
            the_title();
            echo '</li>';
        }
    }
    echo '</ol>';
}
开发者ID:ethicalux,项目名称:kairos_eux,代码行数:44,代码来源:wp_bootstrap_breadcrumbs.php

示例3: get_permalink

 function get_permalink($id = false)
 {
     $rewritecode = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', '%postname%', '%post_id%', '%category%', '%author%', '%pagename%');
     $permalink = get_settings('permalink_structure');
     $postHandler =& wp_handler('Post');
     if ($id) {
         $id = intval($id);
         if ($permalink == '') {
             return wp_siteurl() . '/index.php?p=' . $id;
         }
         if (!isset($GLOBALS['permalink_cache'][wp_id()]) || !isset($GLOBALS['permalink_cache'][wp_id()][$id])) {
             $postObject =& $postHandler->get($id);
             $GLOBALS['permalink_cache'][wp_id()][$id] =& $postObject->exportWpObject();
         }
         $idpost = $GLOBALS['permalink_cache'][wp_id()][$id];
     } else {
         $idpost = $GLOBALS['post'];
     }
     if ('' != $permalink) {
         $unixtime = strtotime($idpost->post_date);
         $cats = get_the_category($idpost->ID);
         $category = $cats[0]->category_nicename;
         $authordata = get_userdata($idpost->post_author);
         $author = $authordata->user_login;
         $rewritereplace = array(date('Y', $unixtime), date('m', $unixtime), date('d', $unixtime), date('H', $unixtime), date('i', $unixtime), date('s', $unixtime), $idpost->post_name, $idpost->ID, $category, $author, $idpost->post_name);
         return wp_siteurl() . str_replace($rewritecode, $rewritereplace, $permalink);
     } else {
         return wp_siteurl() . '/index.php?p=' . $idpost->ID;
     }
 }
开发者ID:BackupTheBerlios,项目名称:nobunobuxoops-svn,代码行数:30,代码来源:template-functions-links.php

示例4: render_related_string

 function render_related_string()
 {
     $settings = C_NextGen_Settings::get_instance();
     $type = $settings->appendType;
     $maxImages = $settings->maxImages;
     $sluglist = array();
     switch ($type) {
         case 'tags':
             if (function_exists('get_the_tags')) {
                 $taglist = get_the_tags();
                 if (is_array($taglist)) {
                     foreach ($taglist as $tag) {
                         $sluglist[] = $tag->slug;
                     }
                 }
             }
             break;
         case 'category':
             $catlist = get_the_category();
             if (is_array($catlist)) {
                 foreach ($catlist as $cat) {
                     $sluglist[] = $cat->category_nicename;
                 }
             }
             break;
     }
     $taglist = implode(',', $sluglist);
     if ($taglist === 'uncategorized' || empty($taglist)) {
         return;
     }
     $renderer = C_Component_Registry::get_instance()->get_utility('I_Displayed_Gallery_Renderer');
     $view = C_Component_Registry::get_instance()->get_utility('I_Component_Factory')->create('mvc_view', '');
     $retval = $renderer->display_images(array('source' => 'tags', 'container_ids' => $taglist, 'display_type' => NEXTGEN_GALLERY_BASIC_THUMBNAILS, 'images_per_page' => $maxImages, 'maximum_entity_count' => $maxImages, 'template' => $view->get_template_abspath('photocrati-nextgen_gallery_display#related'), 'show_all_in_lightbox' => FALSE, 'show_slideshow_link' => FALSE, 'disable_pagination' => TRUE));
     return apply_filters('ngg_show_related_gallery_content', $retval, $taglist);
 }
开发者ID:lcw07r,项目名称:productcampamsterdam.org,代码行数:35,代码来源:adapter.displayed_gallery_related_element.php

示例5: get_gallery_post

function get_gallery_post()
{
    if (isset($_POST['id']) && !empty($_POST['id'])) {
        $projectsCats = array('cocheras', 'terrazas', 'habitaciones', 'antes-despues');
        $id = $_POST['id'];
        $post = get_post($id);
        $gallery = get_post_gallery($post->ID, false);
        $category = get_the_category($post->ID);
        $cat_elements = array();
        $cat_info = array();
        foreach ($projectsCats as $cat) {
            $catdata = get_category_by_slug($cat);
            $args = array('category_name' => $cat, 'orderby' => 'meta_value_num', 'meta_key' => 'order', 'order' => 'ASC', 'posts_per_page' => 3);
            $projects = new WP_Query($args);
            array_push($cat_info, $catdata);
            array_push($cat_elements, $projects);
        }
        if ($gallery !== false) {
            $gallerydata = array();
            $images = explode(',', $gallery['ids']);
            foreach ($images as $key => $image) {
                $imagedata = wp_prepare_attachment_for_js($image);
                array_push($gallerydata, $imagedata);
            }
            $post_info = array('post' => $post, 'category' => $category, 'categories' => $cat_elements, 'cat_info' => $cat_info, 'gallery' => $gallerydata);
            echo json_encode($post_info);
        }
        die;
    } else {
        echo 'error';
        die;
    }
    die;
}
开发者ID:hugobel,项目名称:wp-shadox,代码行数:34,代码来源:functions.php

示例6: show_category

function show_category($cid = 1)
{
    $args = array('showposts' => 4, 'cat' => $cid, 'orderby' => 'post_date', 'order' => 'desc');
    query_posts($args);
    global $the_post;
    $category = '';
    while (have_posts()) {
        the_post();
        $cat = get_the_category(get_the_ID());
        $link = get_permalink(get_the_ID());
        $src = get_the_post_thumbnail(get_the_ID(), 'index_thumb');
        $c_name = $cat[0]->name;
        $title = get_the_title();
        echo $category .= <<<EOF
        <div class="box">
          <a href="{$link}">
          <div class="boximg">{$src}</div>
          <div class="category">{$c_name}</div>
          <p>{$title}</p>
          </a>
        </div>
EOF;
    }
    wp_reset_query();
    return $category;
}
开发者ID:bloemen,项目名称:success,代码行数:26,代码来源:top-category.php

示例7: es_notification_prepare

 public static function es_notification_prepare($post_id = 0)
 {
     global $wpdb;
     $prefix = $wpdb->prefix;
     $arrNotification = array();
     if ($post_id > 0) {
         $post_type = get_post_type($post_id);
         $sSql = "SELECT * FROM `" . $prefix . "es_notification` where (es_note_status = 'Enable' or es_note_status = 'Cron') ";
         if ($post_type == "post") {
             $category = get_the_category($post_id);
             $totcategory = count($category);
             if ($totcategory > 0) {
                 for ($i = 0; $i < $totcategory; $i++) {
                     if ($i == 0) {
                         $sSql = $sSql . " and (";
                     } else {
                         $sSql = $sSql . " or";
                     }
                     $sSql = $sSql . " es_note_cat LIKE '%##" . $category[$i]->cat_name . "##%'";
                     if ($i == $totcategory - 1) {
                         $sSql = $sSql . ")";
                     }
                 }
                 $arrNotification = $wpdb->get_results($sSql, ARRAY_A);
                 //print_r($arrNotification);
             }
         } else {
             $sSql = $sSql . " and es_note_cat LIKE '%##{T}" . $post_type . "{T}##%'";
             $arrNotification = $wpdb->get_results($sSql, ARRAY_A);
             //print_r($arrNotification);
         }
     }
     //die();
     return $arrNotification;
 }
开发者ID:EugenBobrowski,项目名称:email-subscribers,代码行数:35,代码来源:db_notification.php

示例8: related_post_shortcode

function related_post_shortcode($atts, $content = null)
{
    $a = shortcode_atts(array('id' => 0), $atts);
    if ($a['id'] === 0) {
        $categories = get_the_category();
        $category_id = $categories[0]->cat_ID;
        $posts = query_posts(array('showposts' => 1, 'orderby' => 'rand', 'cat' => $category_id, 'date_query' => array('column' => 'post_date', 'after' => '- 90 days')));
        $postID = $posts[0]->ID;
    } else {
        $postID = $a['id'];
    }
    $post = get_post(intval($postID));
    $post_trim = preg_replace('/((\\w+\\W*){16}(\\w+))(.*)/', '${1}', $post->post_content);
    $section_title = get_option('related_post_shortcode_title_custom') ? get_option('related_post_shortcode_title_custom') : __('You may also like', 'related-post-shortcode');
    $excerpt = strip_tags($post_trim) . '...';
    $excerptContainer = get_option('related_post_shortcode_display_excerpt') ? '<div class="rps-excerpt">' . $excerpt . '</div>' : '';
    return '
		<div class="rps-container" >

			<a class="rps-thumb" href="' . get_permalink($postID) . '" >' . get_the_post_thumbnail($postID, 'thumbnail') . '</a>
			<div class="rps-desc">
				<span class="rps-container-title">' . $section_title . '</span>
				<a href="' . get_permalink($postID) . '" class="rps-title">' . get_the_title($postID) . '</a>' . $excerptContainer . '


			</div>
		</div>
	';
}
开发者ID:enguerranws,项目名称:related-post-shortcode,代码行数:29,代码来源:related-post-shortcode.php

示例9: get_post_class

 function get_post_class($class = '', $post_id = null)
 {
     $post = get_post($post_id);
     $classes = array();
     $classes[] = $post->post_type;
     /*
     // sticky for Sticky Posts
     if ( is_sticky($post->ID) && is_home())
     	$classes[] = 'sticky';
     */
     // hentry for hAtom compliace
     $classes[] = 'hentry';
     // Categories
     foreach ((array) get_the_category($post->ID) as $cat) {
         if (empty($cat->slug)) {
             continue;
         }
         $classes[] = 'category-' . $cat->slug;
     }
     // Tags
     foreach ((array) get_the_tags($post->ID) as $tag) {
         if (empty($tag->slug)) {
             continue;
         }
         $classes[] = 'tag-' . $tag->slug;
     }
     if (!empty($class)) {
         if (!is_array($class)) {
             $class = preg_split('#\\s+#', $class);
         }
         $classes = array_merge($classes, $class);
     }
     return apply_filters('post_class', $classes, $class, $post_id);
 }
开发者ID:r15ch13,项目名称:unwakeable,代码行数:34,代码来源:wp-compat.php

示例10: getWordpressData

    static function getWordpressData() {
        /**
         * Get all global page data
         */
        $blogDataParams = array(
            'url', 'wpurl', 'description', 'rdf_url' , 'rss_url', 'rss2_url'
            , 'atom_url', 'comments_atom_url', 'comments_rss2_url', 'pingback_url'
            , 'stylesheet_url', 'stylesheet_directory', 'template_directory'
            , 'template_url', 'admin_email', 'charset', 'html_type', 'version'
            , 'language', 'text_direction', 'name'
        );

        $blogData = array();

        foreach($blogDataParams as $blogDataParam) {
            $blogData[self::toCamelCase($blogDataParam)] = get_bloginfo($blogDataParam);
        }

        $blogData = array_merge($blogData, array(
            'title'            => wp_title(' | ', false, 'right') . get_bloginfo('name'),
            'archiveLinksHTML' => wp_get_archives('type=monthly&limit=5&format=link&echo=0'),
            'bodyClasses'      => self::getEchoFunctionContents('body_class'),
            'posts'            => array()
        ));

        /**
         * Get posts data
         */
        while (have_posts()) {
            the_post();
            
            $postId     = get_the_ID();

            // Get category data
            $categories = get_the_category();
            $categoryNames = array();
            foreach($categories as $category) {
                array_push($categoryNames, $category->cat_name);
            }

            // Add all relevant post data to the posts array
            array_push(
                $blogData['posts'],
                array_merge(
                    get_object_vars(get_post($postId)),
                    array(
                        'classes'       => get_post_class(),
                        'comments'      => get_comments(array('post_id' => $postId)),
                        'custom'        => get_post_custom(),
                        'permalink'     => get_permalink(),
                        'categories'    => $categories,
                        'categoryNames' => $categoryNames,
                        'categoriesStr' => implode(',', $categoryNames)
                    )
                )
            );
        }

        return $blogData;
    }
开发者ID:nottrobin,项目名称:rw-theme,代码行数:60,代码来源:SitesUtil.php

示例11: dtheme_keywords

function dtheme_keywords()
{
    global $s, $post;
    $keywords = '';
    if (is_single()) {
        if (get_the_tags($post->ID)) {
            foreach (get_the_tags($post->ID) as $tag) {
                $keywords .= $tag->name . ', ';
            }
        }
        foreach (get_the_category($post->ID) as $category) {
            $keywords .= $category->cat_name . ', ';
        }
        $keywords = substr_replace($keywords, '', -2);
    } elseif (is_home()) {
        $keywords = dopt('d_keywords');
    } elseif (is_tag()) {
        $keywords = single_tag_title('', false);
    } elseif (is_category()) {
        $keywords = single_cat_title('', false);
    } elseif (is_search()) {
        $keywords = esc_html($s, 1);
    } else {
        $keywords = trim(wp_title('', false));
    }
    if ($keywords) {
        echo "<meta name=\"keywords\" content=\"{$keywords}\" />\n";
    }
}
开发者ID:emperorgod,项目名称:longsays,代码行数:29,代码来源:functions.php

示例12: flatbook_post_metas

 function flatbook_post_metas()
 {
     $user = get_the_author();
     $date = get_the_date('F j');
     $cats = get_the_category();
     $tags = get_the_tags();
     $comm = get_comments_number();
     $type = get_post_format();
     if (false === $type) {
         $type = __('standard', 'flatbook');
     }
     echo '<div class="entry-metas">';
     if ($type) {
         echo '<span class="format"><i class="fa fa-inbox"></i>' . $type . '</span>';
     }
     if ($date) {
         echo '<span class="posted-on"><i class="fa fa-dashboard"></i>' . $date . '</span>';
     }
     if ($user) {
         echo '<span class="byline"><i class="fa fa-user"></i>' . $user . '</span>';
     }
     if ($cats) {
         echo '<span class="cats"><i class="fa fa-folder-open"></i>' . $cats[0]->cat_name . '</span>';
     }
     if ($tags) {
         echo '<span class="tags"><i class="fa fa-tags"></i>' . $tags[0]->name . '</span>';
     }
     if ($comm) {
         echo '<span class="comments"><i class="fa fa-comments"></i>' . $comm . __(' Comment', 'flatbook') . '</span>';
     }
     echo '</div>';
 }
开发者ID:de190909,项目名称:WPTest,代码行数:32,代码来源:template-tags.php

示例13: sourdough_get_categories

 function sourdough_get_categories($sep = ', ', $before = '', $after = '')
 {
     /*
     Echoes the categories with the parent of each as a css class.
     Allows you to style each category link based on it's parent.
     Must be used within the loop.
     
     Example:
         <a href="/category" class="parent-class">cagtegory Name</a>
     */
     $total_cats = count(get_the_category());
     $i = 0;
     foreach (get_the_category() as $cat) {
         ++$i;
         $parent = get_category($cat->parent);
         $link = get_category_link($cat->cat_ID);
         echo $before;
         if (!$parent->errors) {
             echo '<a href="' . $link . '" title="' . $cat->name . '" class="' . $parent->slug . '">' . $cat->name . '</a>';
         } else {
             echo '<a href="' . $link . '" title="' . $cat->name . '">' . $cat->name . '</a>';
         }
         if ($i < $total_cats) {
             echo $sep;
         }
         echo $after;
     }
 }
开发者ID:staydecent,项目名称:wp-sourdough,代码行数:28,代码来源:helpers.php

示例14: build

 /**
  * Build object from posts
  *
  * @param String $posts of HTML to parse
  *
  * @return Mixed collection of posts
  */
 public static function build($posts)
 {
     $collection = [];
     $document = new \DOMDocument();
     $document->loadHTML($posts);
     $iterator = 0;
     $articles = $document->getElementsByTagName("li");
     foreach ($articles as $article) {
         $post = new \StdClass();
         $links = $article->getElementsByTagName("a");
         $images = $article->getElementsByTagName("img");
         $excerpts = $article->getElementsByTagName("small");
         foreach ($links as $link) {
             if (0 == $iterator % 2) {
                 $iterator++;
                 continue;
             }
             $iterator++;
             $post->link = $link->getAttributeNode('href')->value;
             $post->title = $link->textContent;
             $post->category = get_the_category(url_to_postid($post->link))[0]->name;
         }
         foreach ($images as $image) {
             $post->image = $image->getAttributeNode('src')->value;
         }
         foreach ($excerpts as $excerpt) {
             $post->excerpt = $excerpt->textContent;
         }
         $collection[] = $post;
     }
     return $collection;
 }
开发者ID:jsoningram,项目名称:offgrid-framework,代码行数:39,代码来源:FactoryRelated.php

示例15: fetchCategoryPosts

 public function fetchCategoryPosts(SearchArgs $args)
 {
     $i = 0;
     $posts = null;
     $category = $this->fetchCategoryBySlug($args->slug);
     if ($category->getTermid() != null) {
         $search_array = array('posts_per_page' => $args->posts_per_page, 'offset' => $args->offset, 'cat' => $category->getTermid(), 'm' => $args->monthnum, 'orderby' => $args->orderby, 'order' => $args->order);
         query_posts($search_array);
         while (have_posts()) {
             the_post();
             $post = get_post();
             if (!$args->childrenOnly) {
                 $posts[$i++] = new Post($post);
             } else {
                 foreach (get_the_category($post->ID) as $cat) {
                     if ($cat->term_id == $category->getTermid()) {
                         $posts[$i++] = new Post($post);
                         break;
                     }
                 }
             }
         }
         //wp_reset_query();
     }
     return $posts;
 }
开发者ID:rmukras,项目名称:ekda.org,代码行数:26,代码来源:WordPressRepository.php


注:本文中的get_the_category函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。