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


PHP get_category_by_slug函数代码示例

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


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

示例1: pbl_year_filter_dropdown

function pbl_year_filter_dropdown($pub, $category)
{
    global $wp_query;
    $year = isset($wp_query->query['year']) ? $wp_query->query['year'] : date('Y');
    ?>
    <select id="QuRepYear" name="QuRepYear"><?php 
    global $wpdb;
    $term_id = get_term_by('slug', $pub, 'pubcode')->term_id;
    $category_id = get_category_by_slug($category)->term_id;
    $datePosts = $wpdb->get_results($wpdb->prepare("\r\n                    SELECT DISTINCT YEAR( {$wpdb->posts}.post_date ) AS year\r\n                        FROM wp_term_relationships\r\n                        INNER JOIN wp_term_relationships as wptr ON wp_term_relationships.object_id=wptr.object_id and wp_term_relationships.term_taxonomy_id <> wptr.term_taxonomy_id\r\n                        inner join wp_posts on wp_posts.ID = wp_term_relationships.object_id\r\n                        inner join wp_term_taxonomy on wp_term_taxonomy.term_taxonomy_id  = wp_term_relationships.term_taxonomy_id\r\n                        inner join wp_term_taxonomy as wptt on wptt.term_taxonomy_id  = wptr.term_taxonomy_id\r\n                        where (wp_term_taxonomy.term_id = %s and wp_term_taxonomy.taxonomy = 'category')\r\n                            and (wptt.term_id = %s and wptt.taxonomy = 'pubcode')\r\n                            and (wp_posts.post_status = 'publish')\r\n                            ORDER BY year DESC\r\n                ", $category_id, $term_id));
    foreach ($datePosts as $datePost) {
        ?>
        <option <?php 
        echo $datePost->year == $year ? 'selected="selected"' : '';
        ?>
 value="<?php 
        echo $datePost->year;
        ?>
"><?php 
        echo $datePost->year;
        ?>
</option>
    <?php 
    }
    ?>
</select><?php 
}
开发者ID:GabeDiaz,项目名称:responsive-child,代码行数:27,代码来源:functions.php

示例2: get_data

 private function get_data()
 {
     $arguments = array('hide_empty' => false);
     $uncategorized = get_category_by_slug('uncategorized');
     if ($uncategorized) {
         $arguments['category__not_in'] = array($uncategorized->term_id);
     }
     $playboard = array('series' => array(), 'total_all' => 0, 'total ninety' => 0, 'total_thirty' => 0, 'total_seven' => 0);
     /*
     	name, slug, count
     */
     $categories = get_categories();
     $total = 0;
     foreach ($categories as $category) {
         $data = array('name' => $category->name, 'slug' => strtoupper($category->slug), 'count' => $category->category_count);
         $playboard['series'][] = $data;
         $total += $category->category_count;
     }
     $playboard['total_all'] = $total;
     $playboard['total_ninety'] = $this->get_range_total(90);
     $playboard['total_thirty'] = $this->get_range_total(30);
     $playboard['total_seven'] = $this->get_range_total(7);
     $playboard['last_update'] = time();
     return $playboard;
 }
开发者ID:ryanmr,项目名称:convergence-theme,代码行数:25,代码来源:Playboard_Dashboard.php

示例3: company_table

function company_table($side)
{
    if ($side == 'right') {
        $side = 'right_company';
    }
    if ($side == 'left') {
        $side = 'left_company';
    }
    $company_id = get_category_by_slug($side)->term_id;
    query_posts('cat=' . $company_id);
    if (have_posts()) {
        while (have_posts()) {
            the_post();
            global $post;
            $output_home_promos = "";
            $output_home_promos .= "<li class='line'>";
            $output_home_promos .= '<a id="company">';
            $output_home_promos .= "<span class='heading'>" . $post->post_title . "</span>";
            $output_home_promos .= "<span class='summary'>" . $post->post_content . "</span>";
            $output_home_promos .= "</a>";
            $output_home_promos .= "</li>";
            if (!empty($output_home_promos)) {
                $output_home_promos = "<ul class='large'>" . $output_home_promos . "</ul>";
            }
            echo $output_home_promos;
        }
    }
}
开发者ID:nunomorgadinho,项目名称:widgilabs.com,代码行数:28,代码来源:functions.php

示例4: test_get_category_by_slug

	/**
	 * Validate get_category_by_slug function
	 */
	function test_get_category_by_slug() {

		// create Test Categories
		$testcat = $this->factory->category->create_and_get(
			array(
				'slug' => 'testcat',
				'name' => 'Test Category 1'
			)
		);
		$testcat2 = $this->factory->category->create_and_get(
			array(
				'slug' => 'testcat2',
				'name' => 'Test Category 2'
			)
		);

		// validate category is returned by slug
		$ret_testcat = get_category_by_slug( 'testcat' );
		$this->assertEquals( $testcat->term_id, $ret_testcat->term_id );
		$ret_testcat = get_category_by_slug( 'TeStCaT' );
		$this->assertEquals( $testcat->term_id, $ret_testcat->term_id );

		// validate unknown category returns false
		$this->assertFalse( get_category_by_slug( 'testcat3' ) );

	}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:29,代码来源:category.php

示例5: search_handler

 static function search_handler()
 {
     if (strtok($_SERVER["REQUEST_URI"], '?') == '/search') {
         load_template(plugin_dir_path(__FILE__) . 'page-search.php');
         exit;
     }
     if (strtok($_SERVER["REQUEST_URI"], '?') == '/search-request') {
         $search_options = array('s' => $_GET['s'], 'post_type' => 'post');
         if ($_GET['cat']) {
             $search_options['cat'] = get_category_by_slug($_GET['cat'])->term_id;
         }
         if ($_GET['author']) {
             $search_options['author_name'] = $_GET['author'];
         }
         $search_options['paged'] = $_GET['page'] ? $_GET['page'] : 1;
         $search_options['posts_per_page'] = 3;
         $searched_posts = new WP_Query($search_options);
         $show_more_link = $searched_posts->max_num_pages > $search_options['paged'];
         if ($search_options['paged'] > 1) {
             include 'search-more.php';
         } else {
             include 'search.php';
         }
         exit;
     }
 }
开发者ID:rexington,项目名称:theopenstandard,代码行数:26,代码来源:the-open-standard-search.php

示例6: 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

示例7: echoSidebar

function echoSidebar($category)
{
    $title = get_category_by_slug($category);
    echo "<div id='sidebar'>\n\t<div id='text-block'>\n\t\t<div class='top-shadow'>\n\t\t\t<h4>";
    echo $title->name;
    echo " </h4>\n\t\t</div>\n\t\t<div class='center'>\n\t\t\t<div class='text-entry'>\n\t\t\t\t<p>";
    _e('Более детальная информация:', 'dpm');
    echo "</p>\n\t\t\t\t<ul>\n\t\t\t\t";
    $the_query = new WP_Query(array('category_name' => $category));
    while ($the_query->have_posts()) {
        $the_query->the_post();
        echo '<li>
			<a class="news-head" href="';
        the_permalink();
        echo '">';
        the_title();
        echo '</a>
			</li>';
    }
    echo '</ul>
			</div>
		<div class="bottom-shadow">
	   </div>
 </div>
</div>';
}
开发者ID:MaryMaffka,项目名称:dpm,代码行数:26,代码来源:functions.php

示例8: loop_category

function loop_category($category)
{
    $idObj = get_category_by_slug($category);
    $cat_name = $idObj->name;
    if ($category === 'news') {
        $number = 4;
    } else {
        $number = 1;
    }
    $args = array('posts_per_page' => $number, 'category_name' => $category);
    $posts_array = get_posts($args);
    $length = count($posts_array);
    if ($length > 0) {
        echo '<a href="' . get_category_link($idObj->cat_ID) . ' " ><h3 class="big-article-title">' . $cat_name . '</h3></a>';
        global $post;
        foreach ($posts_array as $key => $post) {
            setup_postdata($post);
            if ($key === 0) {
                get_template_part('templates/content', get_post_type() != 'post' ? get_post_type() : get_post_format());
            } else {
                if ($key === 1) {
                    echo '<ul class="other-post-list length' . ($length - 1) . '">';
                }
                get_template_part('templates/content', 'post-intro');
                if ($key === $length) {
                    echo '</ul>';
                }
            }
        }
        wp_reset_postdata();
    }
}
开发者ID:Kilbourne,项目名称:bedrock,代码行数:32,代码来源:extras.php

示例9: asa_inne_ute_widget

function asa_inne_ute_widget($args)
{
    // extract the arg passed by theme
    extract($args);
    // get option (picture url)
    $options = get_option("asa_inne_ute_picture_url_widget");
    //get latest inne-ute
    $myposts = get_posts('numberposts=1&category=' . get_category_by_slug('inne-utelistan')->term_id . '&order=DESC&orderby=date');
    // get the latest list
    foreach ($myposts as $inne_post) {
        $latest_inne_ute = $inne_post->guid;
    }
    // not sure if we need theese extracted args but it is said to be good for compability
    // widget layout with img scr url set by options.
    ?>

<div class="r_side">
  <div id="inneutelista">
    <a title="Inne- och utelistan" href="<?php 
    echo $latest_inne_ute;
    ?>
">
    <img alt="Till Åsas kungliga inne- och utelista" src="<?php 
    echo $options['asa_inne_ute_picture_url'];
    ?>
" title="Till Åsas kungliga inne- och utelista"/></a>
  </div>
</div>

<?php 
}
开发者ID:allerinternet,项目名称:wp-plugins-oss,代码行数:31,代码来源:AI-asa-inne-ute.php

示例10: widget

    public function widget($args, $instance)
    {
        $post_cat = $instance['post_cat'];
        $post_num = $instance['post_num'];
        $post_slug = get_category_by_slug($post_cat);
        echo $args['before_widget'];
        echo $args['before_title'];
        echo $post_slug->name;
        echo $args['after_title'];
        echo '<ul class="widget-post">';
        $widgetPost = new WP_Query(array('post_type' => 'post', 'category_name' => $post_cat, 'posts_per_page' => $post_num));
        global $post;
        if ($widgetPost->have_posts()) {
            while ($widgetPost->have_posts()) {
                $widgetPost->the_post();
                ?>
        <li class="widget-post__list">
            <a href="<?php 
                the_permalink();
                ?>
" class="clearfix">
                <div class="widget-post__thumb">
                    <?php 
                the_post_thumbnail('thumb_s', array('class' => 'thumb'));
                ?>
                </div>
                <div class="widget-post__body">
                    <h3 class="widget-post__title">
                        <?php 
                if (mb_strlen($post->post_title) > 35) {
                    $title = mb_substr($post->post_title, 0, 35);
                    echo $title . '...';
                } else {
                    echo $post->post_title;
                }
                ?>
                    </h3>
                </div>
            </a>
        </li>
        <?php 
            }
            echo '</ul>';
            ?>
        <div class="widget-post__more">
            <a href="<?php 
            echo home_url('/') . $post_cat;
            ?>
">すべて読む<i class="fa fa-chevron-circle-right"></i></a>
        </div>
        <?php 
        } else {
            ?>
        <p>投稿なし</p>
        <?php 
        }
        wp_reset_query();
        echo $args['after_widget'];
    }
开发者ID:conscious-jp,项目名称:website,代码行数:59,代码来源:PostWidget.php

示例11: get_children_categories

function get_children_categories($parent_slug)
{
    $c = get_category_by_slug($parent_slug);
    if ($c) {
        $category_id = $c->term_id;
        return get_categories(array('child_of' => $category_id));
    }
}
开发者ID:BlessySoftwares,项目名称:anvelocom,代码行数:8,代码来源:functions.php

示例12: migrate_blog

function migrate_blog()
{
    /*
         * $tabRub[0] = "Annonces";
        $tabRub[1] = "Partenariat";
        $tabRub[2] = "Vie d'Anciela";
        $tabRub[3] = "Autres";
         * */
    $categories = array('annonces', 'partenariat', 'anciela', 'autres');
    $categoryNames = array('annonces' => "Annonces", 'partenariat' => 'Partenariats', 'anciela' => "Vie d'anciela", 'autres' => 'Autres');
    foreach ($categoryNames as $categorySlug => $categoryName) {
        wp_insert_term($categoryName, 'category', array('slug' => $categorySlug));
    }
    $db = mysqli_connect("localhost", "root", "", "db161162332") or die("Error " . mysqli_error($link));
    // Setup the author, slug, and title for the post
    $author_id = 1;
    $args = array('post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => null);
    $attachments = get_posts($args);
    $db->query('set names utf8');
    $db->query("SET character_set_connection = 'UTF8'");
    $db->query("SET character_set_client = 'UTF8'");
    $db->query("SET character_set_results = 'UTF8'");
    $result = $db->query("select * from `anc_info_blog`");
    while ($row = $result->fetch_array()) {
        $categoryIntId = $row["rub_blog"] - 1;
        $category = $categories[$categoryIntId];
        $category = get_category_by_slug($category);
        if ($category) {
            $category = $category->term_id;
        }
        $title = stripslashes($row["titre_blog"]);
        $date = $row["date_pub_deb_blog"];
        $content = stripslashes($row['texte_blog']);
        $img = $row['image_blog'];
        $align = $row['image_pos_blog'] == 0 ? 'center' : 'right';
        if ($img) {
            foreach ($attachments as $post) {
                setup_postdata($post);
                the_title();
                $mediaTitle = $post->post_title;
                $img = explode('.', $img)[0];
                if ($mediaTitle == $img) {
                    $id = $post->ID;
                    $content = '[image id="' . $id . '" align="' . $align . '"]<br/>' . $content;
                }
                /*$dataToSave = array(
                      'ID' => $post->ID,
                      'post_title' =>
                  );
                  wp_update_post($dataToSave);*/
            }
        }
        if (null == get_page_by_title($title, null, 'post')) {
            wp_insert_post(array('comment_status' => 'open', 'ping_status' => 'closed', 'post_author' => $author_id, 'post_title' => $title, 'post_status' => 'publish', 'post_type' => 'post', 'post_category' => array($category), 'post_date' => $date . ' 12:00:00', 'post_content' => $content));
        }
    }
    mysqli_close($db);
}
开发者ID:Anciela,项目名称:anciela.info,代码行数:58,代码来源:anciela-setup.php

示例13: category_id_from_slug

 function category_id_from_slug($slug)
 {
     $category = get_category_by_slug($slug);
     if ($category) {
         return $category->term_id;
     } else {
         return null;
     }
 }
开发者ID:esskabar,项目名称:wp-skeletor,代码行数:9,代码来源:functions.php

示例14: list_type

function list_type($category, $type)
{
    echo "<h1>" . get_cat_name(get_category_by_slug($category)->cat_ID) . ":</h1>\n";
    $files = new WP_Query(array('category_name' => $category, 'post_type' => $type, 'order' => 'ASC', 'orderby' => 'title'));
    while ($files->have_posts()) {
        $files->the_post();
        echo "<p>" . the_post_thumbnail() . "<strong>" . get_the_title() . "</strong>: " . get_the_content() . "</p>\n";
    }
}
开发者ID:cael421,项目名称:arbiter-prime,代码行数:9,代码来源:functions.php

示例15: pmc_eve_query_category

/**
 * Remove the featured category on the home page main query
 * @param WP_Query $query
 * @since 1.2
 */
function pmc_eve_query_category($query)
{
    if ($query->is_home() && $query->is_main_query()) {
        $cat = get_category_by_slug('featured');
        if ($cat) {
            $query->set('cat', '-' . $cat->term_id);
        }
    }
}
开发者ID:priscillamc,项目名称:pmc-eve,代码行数:14,代码来源:extras.php


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