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


PHP Posts::count_by_tag方法代码示例

本文整理汇总了PHP中Posts::count_by_tag方法的典型用法代码示例。如果您正苦于以下问题:PHP Posts::count_by_tag方法的具体用法?PHP Posts::count_by_tag怎么用?PHP Posts::count_by_tag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Posts的用法示例。


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

示例1: rewrite_tag_exists

 /**
  * Check if a tag exists on a published post, to see if we should match this rewrite rule.
  *
  * @return Boolean Whether the tag exists on a published post.
  */
 public static function rewrite_tag_exists($rule, $slug, $parameters)
 {
     $tags = explode(' ', $rule->named_arg_values['tag']);
     $tags = array_map('trim', $tags, array_fill(0, count($tags), '-'));
     $tags = array_map(array('Tags', 'get_one'), $tags);
     $initial_tag_count = count($tags);
     $tags = array_filter($tags);
     // Are all of the tags we asked for actual tags on this site?
     if (count($tags) != $initial_tag_count) {
         return false;
     }
     $tag_params = array();
     foreach ($tags as $tag) {
         $tag_params[] = $tag->term_display;
     }
     return $tag instanceof Term && Posts::count_by_tag($tag_params, Post::status('published')) > 0;
 }
开发者ID:wwxgitcat,项目名称:habari,代码行数:22,代码来源:tag.php

示例2: action_block_content_tag_archives

 /**
  * Tag Archives
  *
  * Handle tag archive block output
  *
  * @param Block $block The block instance to be configured
  * @param Theme $theme The active theme
  */
 public function action_block_content_tag_archives($block, $theme)
 {
     $tags = array();
     $results = Tags::vocabulary()->get_tree();
     foreach ($results as $result) {
         $count = '';
         if ($block->show_counts) {
             $count = " (" . Posts::count_by_tag($result->term_display, "published") . ")";
         }
         $url = URL::get('display_entries_by_tag', array('tag' => $result->term));
         $tags[] = array('tag' => $result->term_display, 'count' => $count, 'url' => $url);
     }
     $block->tags = $tags;
 }
开发者ID:wwxgitcat,项目名称:habari,代码行数:22,代码来源:coreblocks.plugin.php

示例3: _e

        echo "<li><a href=\"{$page->permalink}\" title=\"{$page->title}\">{$page->title}</a></li>";
    }
    ?>
    </ul>
    <?php 
}
if ($tags) {
    ?>
    <h2><?php 
    _e('Tags');
    ?>
</h2>
    <ul>
      <?php 
    foreach ($tags as $tag) {
        $tag_count = Posts::count_by_tag($tag->tag, 'published');
        echo "<li><a href=\"" . URL::get('display_entries_by_tag', 'tag=' . $tag->slug) . "\">{$tag->tag}</a></li>";
    }
    ?>
   </ul>
  <?php 
}
?>

  <h2><?php 
_e('Meta');
?>
</h2>
  <ul>
    <?php 
if ($loggedin) {
开发者ID:habari-extras,项目名称:phoenixblue,代码行数:31,代码来源:sidebar.php

示例4: test_get_posts_by_tag

 /**
  * Get posts by tag
  */
 public function test_get_posts_by_tag()
 {
     // setup
     $tags = array();
     if (Tags::vocabulary()->get_term("laser")) {
         Tags::vocabulary()->delete_term("laser");
     }
     if (Tags::vocabulary()->get_term("dog")) {
         Tags::vocabulary()->delete_term("dog");
     }
     if (Tags::vocabulary()->get_term("name")) {
         Tags::vocabulary()->delete_term("name");
     }
     $tags[] = Tags::vocabulary()->add_term("laser");
     $five_tags = array("mattress", "freeze", "DOG", "Name", "hash");
     foreach ($five_tags as $tag) {
         $tags[] = Tags::vocabulary()->add_term($tag);
         $count_before[$tag] = Posts::get(array('vocabulary' => array('tags:term' => $tag), 'count' => 'DISTINCT {posts}.id', 'ignore_permissions' => true, 'nolimit' => 1));
     }
     for ($i = 1; $i <= 15; $i++) {
         $post_tags = array();
         for ($j = 0; $j < 5; $j++) {
             if ($i % ($j + 2) == 0) {
                 $post_tags[] = $five_tags[$j];
             }
         }
         $post = Post::create(array('title' => "Test post {$i}", 'content' => count($post_tags) . " tags: " . implode(', ', $post_tags), 'user_id' => $this->user->id, 'status' => Post::status('published'), 'tags' => $post_tags, 'content_type' => Post::type('entry'), 'pubdate' => DateTime::date_create(time())));
         $post->info->testing_tag = 1;
         $post->info->commit();
     }
     /**
      * At this point, these are the posts and their tags:
      *  1 (no tags)
      *  2: mattress
      *  3: freeze
      *  4: mattress, DOG
      *  5: Name
      *  6: mattress, freeze, hash
      *  7 (no tags)
      *  8: mattress, DOG
      *  9: freeze
      * 10: mattress, Name
      * 11 (no tags)
      * 12: mattress, freeze, DOG, hash
      * 13 (no tags)
      * 14: mattress
      * 15: freeze, Name
      */
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n                LEFT JOIN {object_terms} o ON p.id = o.object_id\n\t\t\t\tWHERE o.term_id IN (\n\t\t\t\t\tSELECT id FROM {terms} WHERE term_display = 'DOG'\n\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM vocabularies WHERE name = 'tags' )\n\t\t\t\t)\n\t\t\t");
     // tags:term_display
     $post_count = Posts::get(array('vocabulary' => array('tags:term_display' => 'DOG'), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     $post_count = Posts::count_by_tag('DOG', Post::status('published'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Posts::count_by_tag(): {$post_count}");
     // tags:term
     $post_count = Posts::get(array('vocabulary' => array('tags:term' => 'dog'), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n                LEFT JOIN {object_terms} o ON p.id = o.object_id\n\t\t\t\tWHERE o.term_id IN (\n\t\t\t\t\tSELECT id FROM {terms} WHERE term = 'name'\n\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM vocabularies WHERE name = 'tags' )\n\t\t\t\t)\n\t\t\t");
     $post_count = Posts::get(array('vocabulary' => array('tags:term' => 'name'), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n                LEFT JOIN {object_terms} o ON\n                    p.id = o.object_id\n\t\t\t\tWHERE o.term_id IN (\n\t\t\t\t\tSELECT id FROM {terms} WHERE term in ( 'mattress', 'freeze' )\n\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' )\n\t\t\t\t)\n\t\t\t");
     $post_count = Posts::get(array('vocabulary' => array('tags:term' => array('mattress', 'freeze')), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     // tags:all:term
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n\t\t\t\tWHERE id IN (\n\t\t\t\t\tSELECT o1.object_id FROM {object_terms} o1\n\t\t\t\t\t\tLEFT JOIN {object_terms} o2 ON\n\t\t\t\t\t\t\to1.object_id = o2.object_id AND\n\t\t\t\t\t\t\to1.term_id != o2.term_id\n\t\t\t\t\tWHERE\n\t\t\t\t\t\to1.term_id = ( SELECT id FROM {terms} WHERE term = 'mattress'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) ) AND\n\t\t\t\t\t\to2.term_id = ( SELECT id FROM {terms} WHERE term = 'freeze'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t");
     $any_count = $post_count;
     $post_count = count(Posts::get(array('vocabulary' => array('tags:all:term' => array('mattress', 'freeze')), 'ignore_permissions' => true, 'nolimit' => 1)));
     $this->assert_not_equal($any_count, $post_count, "Any: {$any_count} All: {$post_count}");
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     // tags:all:term_display
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n\t\t\t\tWHERE id IN (\n\t\t\t\t\tSELECT o1.object_id FROM {object_terms} o1\n\t\t\t\t\t\tLEFT JOIN {object_terms} o2 ON\n\t\t\t\t\t\t\to1.object_id = o2.object_id AND\n\t\t\t\t\t\t\to1.term_id != o2.term_id\n\t\t\t\t\tWHERE\n\t\t\t\t\t\to1.term_id = ( SELECT id FROM {terms} WHERE term_display = 'Name'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) ) AND\n\t\t\t\t\t\to2.term_id = ( SELECT id FROM {terms} WHERE term_display = 'DOG'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t");
     $any_count = $post_count;
     $post_count = Posts::get(array('vocabulary' => array('tags:all:term' => array('Name', 'DOG')), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_not_equal($any_count, $post_count, "Any: {$any_count} All: {$post_count}");
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     // tags:not:term
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n\t\t\t\tWHERE id NOT IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term = 'laser'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t");
     $post_count = Posts::get(array('vocabulary' => array('tags:not:term' => 'laser'), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n\t\t\t\tWHERE id NOT IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term = 'mattress'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t\tAND id NOT IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term = 'freeze'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t");
     $post_count = Posts::get(array('vocabulary' => array('tags:not:term' => array('mattress', 'freeze')), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n\t\t\t\tWHERE id NOT IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term = 'laser'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t\tAND id IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term = 'mattress'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t");
     $post_count = Posts::get(array('vocabulary' => array('tags:not:term' => 'laser', 'tags:term' => 'mattress'), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     // tags:not:term_display
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n\t\t\t\tWHERE id NOT IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term_display = 'DOG'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t\tAND id IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term = 'mattress'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t");
     $post_count = Posts::get(array('vocabulary' => array('tags:not:term_display' => 'DOG', 'tags:term' => 'mattress'), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     $sql_count = DB::get_value("SELECT COUNT(DISTINCT id) FROM {posts} p\n\t\t\t\tWHERE id NOT IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term_display = 'DOG'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t\tAND id NOT IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term = 'freeze'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t\tAND id IN (\n\t\t\t\t\tSELECT object_id FROM {object_terms}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tterm_id in ( SELECT id FROM {terms} WHERE term = 'mattress'\n\t\t\t\t\t\t\tAND vocabulary_id = ( SELECT id FROM {vocabularies} WHERE name = 'tags' ) )\n\t\t\t\t)\n\t\t\t");
     $post_count = Posts::get(array('vocabulary' => array('tags:not:term_display' => array('DOG', 'freeze'), 'tags:term' => 'mattress'), 'ignore_permissions' => true, 'nolimit' => 1, 'count' => 'DISTINCT {posts}.id'));
     $this->assert_equal($sql_count, $post_count, "SQL: {$sql_count} Post: {$post_count}");
     // teardown
     Posts::get(array('ignore_permissions' => true, 'has:info' => 'testing_tag', 'nolimit' => 1))->delete();
     foreach ($tags as $tag) {
         Tags::vocabulary()->delete_term($tag);
     }
//.........这里部分代码省略.........
开发者ID:habari,项目名称:tests,代码行数:101,代码来源:test_posts.php

示例5: add_count

 private function add_count(&$tag)
 {
     if (in_array($tag->tag_text[0], $this->prefix)) {
         return false;
     }
     $tag->count = Posts::count_by_tag($tag->slug, "published");
     $tag->step = ceil($tag->count / $this->step);
     return $tag;
 }
开发者ID:habari-extras,项目名称:fluffytag,代码行数:9,代码来源:fluffytag.plugin.php


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