本文整理汇总了PHP中set_query_var函数的典型用法代码示例。如果您正苦于以下问题:PHP set_query_var函数的具体用法?PHP set_query_var怎么用?PHP set_query_var使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_query_var函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: limit_posts_per_archive_page
function limit_posts_per_archive_page()
{
if (is_category(31)) {
set_query_var('posts_per_archive_page', 5);
}
// or use variable key: posts_per_page
}
示例2: index
public function index($page = 1)
{
global $paged;
$page_id = get_option('page_for_posts');
if ($page < 0) {
$page = 1;
}
set_query_var('paged', $page);
if ($page_id > 0) {
$layout = get_post_meta($page_id, '_layout', true);
if (empty($layout) || !$this->view->check_layout($layout)) {
$layout = $this->core->get_option('blog_layout', 'content_right');
}
$page_title = get_the_title($page_id);
$page_tagline = get_post_meta($page_id, '_page_tagline', true);
if (!get_post_meta($page_id, '_disable_page_title', true)) {
$this->view->add_block('page_title', 'general/page_title', array('page_title' => $page_title, 'page_tagline' => $page_tagline));
}
if (!get_post_meta($page_id, '_disable_breadcrumbs', true)) {
$this->breadcrumbs->add_item($page_title . ' ' . $page_tagline, get_permalink($page_id));
}
} else {
// THEME SETTINGS
$this->view->add_block('page_title', 'general/page_title', array('page_title' => $this->core->get_option('blog_title')));
$layout = $this->core->get_option('blog_layout', 'content_right');
}
//$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$paginator = $this->load->library('paginator');
$paginator = $paginator->get(3, wp_count_posts()->publish, get_option('posts_per_page'), 1, 2, 'blog/page/' . $page, 'blog/');
$this->view->use_layout('header_' . $layout . '_footer')->add_block('content', 'blog/view', array('layout' => $layout))->add_block('content/pagination', 'general/pagination', $paginator);
}
示例3: getLastPosts
public function getLastPosts($atts)
{
extract(shortcode_atts(array('kategorie' => 'post', 'anzahl' => 3, 'zeichen' => 250), $atts));
global $wpdb;
$sql = 'SELECT p.ID, p.post_title, p.guid, p.post_content
FROM ' . $wpdb->prefix . 'terms
INNER JOIN ' . $wpdb->prefix . 'term_taxonomy ON ' . $wpdb->prefix . 'terms.term_id = ' . $wpdb->prefix . 'term_taxonomy.term_id
INNER JOIN ' . $wpdb->prefix . 'term_relationships AS wpr ON wpr.term_taxonomy_id = ' . $wpdb->prefix . 'term_taxonomy.term_taxonomy_id
INNER JOIN ' . $wpdb->prefix . 'posts AS p ON p.ID = wpr.object_id
WHERE p.post_type = "post"
AND ' . $wpdb->prefix . 'term_taxonomy.taxonomy = "category"
AND ' . $wpdb->prefix . 'terms.name = "' . $kategorie . '"
AND p.post_status = "publish"
ORDER BY p.post_date
DESC LIMIT ' . $anzahl;
$result = $wpdb->get_results($sql);
$lastPosts = array();
if ($result) {
foreach ($result as $key => $row) {
if ((int) $zeichen === 0) {
$row->read_more = 0;
} else {
$postContent = strip_tags($row->post_content);
//Alle HTML Tags entfernen. Nur reinen Text anzeigen lassen.
$row->post_content = substr($postContent, 0, $zeichen);
//Ausgabe begrenzen
$row->read_more = 1;
}
set_query_var('singlePost', $row);
get_template_part('partials/single');
}
}
}
示例4: render
public function render($properties)
{
?>
<div class="module module--padded">
<?php
$moduleIdentifier = "selectedModules_" . chr(rand(65, 90)) . chr(rand(65, 90)) . chr(rand(65, 90)) . chr(rand(65, 90)) . chr(rand(65, 90));
$fagmod = new Fagmoduler();
if (is_page_template('gode-erfaringer-children.php')) {
$field_fornavn = get_field('fornavn', get_the_ID());
if ($field_fornavn) {
print '<h3>' . $properties['headline'] . ' som ' . $field_fornavn . '</h3>';
} else {
print '<h3>' . $properties['headline'] . '</h3>';
}
} else {
print '<h2>' . $properties['headline'] . '</h2>';
}
$fagList = array();
foreach ($properties['modules'] as $modul) {
$fag = $fagmod->getFag(get_field("fag_id", $modul['module_post']->ID));
$fagList[] = $fag;
}
?>
<script>
var <?php
print $moduleIdentifier;
?>
= <?php
print json_encode($fagList);
?>
;
</script>
<div class="accordion accordion--trade panel-group" ng-controller="SelectedModulesCtrl as <?php
print $moduleIdentifier;
?>
" ng-init="<?php
print $moduleIdentifier;
?>
.init('<?php
print $moduleIdentifier;
?>
')">
<?php
set_query_var('moduleIdentifier', $moduleIdentifier);
get_template_part('parts/fagmoduler-accordion-part');
?>
</div>
</div>
<?php
}
示例5: wp
public function wp(WP $WP)
{
if (is_404() && ($class_name = $this->get_404_class_name())) {
} elseif (is_search() && ($class_name = $this->get_search_class_name())) {
} elseif (is_front_page() && ($class_name = $this->get_front_page_class_name())) {
} elseif (is_home() && ($class_name = $this->get_home_class_name())) {
} elseif (is_post_type_archive() && ($class_name = $this->get_post_type_archive_class_name())) {
} elseif (is_tax() && ($class_name = $this->get_taxonomy_class_name())) {
// elseif (is_attachment() && $class_name = $this->get_attachment_class_name()):
} elseif (is_page() && ($class_name = $this->get_page_class_name())) {
} elseif (is_single() && ($class_name = $this->get_single_class_name())) {
} elseif (is_category() && ($class_name = $this->get_category_class_name())) {
} elseif (is_tag() && ($class_name = $this->get_tag_class_name())) {
} elseif (is_author() && ($class_name = $this->get_author_class_name())) {
} elseif (is_date() && ($class_name = $this->get_date_class_name())) {
// elseif (is_comments_popup() && $class_name = $this->get_comments_popup_class_name()):
// elseif (is_paged() && $class_name = $this->get_paged_class_name()):
} else {
$class_name = $this->get_index_class_name();
}
// must use Autoloader
if ($class_name && class_exists($class_name)) {
set_query_var($this->class_data['store_name'], new $class_name());
}
return;
}
示例6: changept
function changept()
{
if (is_category() && !is_admin()) {
set_query_var('post_type', array('post', 'category'));
}
return;
}
示例7: Dashboard
/**
* @usage Short-code function for front-end UI
* @return string
*/
function Dashboard()
{
global $current_user;
wp_reset_query();
$currentAccess = maybe_unserialize(get_option('__wpdm_front_end_access', array()));
$task = get_query_var('adb_page');
$task = explode("/", $task);
if ($task[0] == 'edit-package') {
$pid = $task[1];
}
if ($task[0] == 'page') {
$task[0] = '';
set_query_var('paged', $task[1]);
}
$task = $task[0];
if (!array_intersect($currentAccess, $current_user->roles) && is_user_logged_in()) {
return "<div class='w3eden'><div class='alert alert-danger'>" . wpautop(stripslashes(get_option('__wpdm_front_end_access_blocked', __('Sorry, Your Are Not Allowed!', 'wpdmpro')))) . "</div></div>";
}
$id = wpdm_query_var('ID');
$tabs = array();
$tabs = apply_filters('wpdm_frontend', $tabs);
$burl = get_permalink();
$sap = strpos($burl, '?') ? '&' : '?';
ob_start();
include \WPDM\Template::Locate('author-dashboard.php');
$data = ob_get_clean();
return $data;
}
示例8: process
public static function process()
{
theme_features::check_referer();
$post_id = isset($_GET['post-id']) && is_numeric($_GET['post-id']) ? (int) $_GET['post-id'] : false;
if (!$post_id) {
die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_post_id', 'msg' => ___('Sorry, post id is invaild.')]));
}
global $post, $page;
/**
* post
*/
$post = theme_cache::get_post($post_id);
if (!$post) {
die(theme_features::json_format(['status' => 'error', 'code' => 'post_not_exist', 'msg' => ___('Sorry, the post does not exist.')]));
}
/**
* page
*/
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int) $_GET['page'] : false;
if (!$page) {
die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_page_number', 'msg' => ___('Sorry, page number is invaild.')]));
}
set_query_var('page', $page);
setup_postdata($post);
ob_start();
if (class_exists('theme_img_lazyload')) {
remove_filter('the_content', 'theme_img_lazyload::the_content');
}
the_content();
$content = html_minify(ob_get_contents());
ob_end_clean();
die(theme_features::json_format(['status' => 'success', 'content' => $content]));
}
示例9: testThePosts
public function testThePosts()
{
global $wp_query;
$this->assertNull($this->frontend->thePosts(null));
set_query_var('is_search', false);
$posts = array();
$posts[] = new WP_Post();
$posts[] = new WP_Post();
$this->assertEquals($this->frontend->thePosts($posts), $posts);
set_query_var('is_search', true);
set_query_var('is_admin', true);
$this->assertEquals($this->frontend->thePosts($posts), $posts);
set_query_var('is_search', true);
set_query_var('is_admin', false);
$this->assertNotEquals($this->frontend->thePosts($posts), $posts);
$post = new WP_Post();
$post->ID = 3;
$posts = array($post);
set_query_var('is_main_query', true);
$wp_query->is_main_query = true;
$wp_query->is_search = true;
$wp_query->is_admin = false;
$wp_query->query['s'] = 'aliyun';
$this->aliyunOpenSearchClient->shouldReceive('search')->andReturn(array('posts' => $posts, 'total' => 1))->once();
$this->frontend->preGetPosts($wp_query);
$this->assertEquals($this->frontend->thePosts($posts), $posts);
}
示例10: display
/**
* Display related posts
*/
public function display()
{
$posts = $this->get_related_posts();
if (empty($posts)) {
return;
}
global $post, $wp_query;
$default_query = clone $wp_query;
set_query_var('is_related', true);
?>
<div class="related-posts">
<h2 class="related-posts__title h3"><?php
_e('Related posts', 'habakiri');
?>
</h2>
<div class="entries entries--related-posts entries-related-posts">
<?php
foreach ($posts as $post) {
setup_postdata($post);
get_template_part('content', 'summary');
}
wp_reset_postdata();
?>
</div>
</div>
<?php
$wp_query = $default_query;
}
示例11: nimbus_cotizador
function nimbus_cotizador($atts, $content)
{
extract($atts);
set_query_var('success', $action);
$template = locate_template("/templates/quote.php");
load_template($template);
}
示例12: spun_limit_posts_per_archive_page
/**
* Filter archives to display one less post per page to account for the .page-title circle
*/
function spun_limit_posts_per_archive_page()
{
if (!is_home() && is_archive() || is_search()) {
$posts_per_page = intval(get_option('posts_per_page')) - 1;
set_query_var('posts_per_page', $posts_per_page);
}
}
示例13: wpex_blog_exclude_categories
function wpex_blog_exclude_categories()
{
// Wait..we don't want to be in these plages? Lets leave now!
if (is_admin()) {
return;
}
if (is_search()) {
return;
}
if (is_archive()) {
return;
}
// Categories to exclude
$cats_to_exclude = wpex_option('blog_cats_exclude');
// Admin option is blank, so bail.
if ($cats_to_exclude == '') {
return;
}
// Blog template
if (is_home() && !is_singular('page')) {
$exclude = $cats_to_exclude;
} else {
return;
// Do nothing, ok?
}
if ($cats_to_exclude) {
set_query_var('category__not_in', $cats_to_exclude);
}
}
示例14: widget
function widget($args, $instance)
{
// Turn $args array into variables.
extract($args);
// $instance Defaults
$instance_defaults = $this->defaults;
// Parse $instance
$instance = wp_parse_args($instance, $instance_defaults);
// Options output
$section_title = !empty($instance['title']) ? $instance['title'] : '';
set_query_var('section_title', strip_tags($section_title));
$spo = !empty($instance['show_pos']) ? 1 : 0;
set_query_var('spo', absint($spo));
$sco = !empty($instance['show_com']) ? 1 : 0;
set_query_var('sco', absint($sco));
$sca = !empty($instance['show_cat']) ? 1 : 0;
set_query_var('sca', absint($sca));
$sda = !empty($instance['show_date']) ? 1 : 0;
set_query_var('sda', absint($sda));
$cnmt = !empty($instance['css_no_mt']) ? 1 : 0;
$cnmb = !empty($instance['css_no_mb']) ? 1 : 0;
$cbot = !empty($instance['css_b_top']) ? 1 : 0;
$cbob = !empty($instance['css_b_bot']) ? 1 : 0;
$cpat = !empty($instance['css_p_top']) ? 1 : 0;
// Widget styling based on options
$css_class = array();
if ($cnmt) {
$css_class[] = 'n-mt';
}
if ($cnmb) {
$css_class[] = 'n-mb';
}
if ($cbot) {
$css_class[] = 'b-top';
}
if ($cbob) {
$css_class[] = 'b-bot';
}
if ($cpat) {
$css_class[] = 'p-top';
}
$css_classes = join(' ', $css_class);
if (!empty($css_classes)) {
if (strpos($args['before_widget'], 'class') === false) {
$args['before_widget'] = str_replace('>', 'class="' . esc_attr($css_classes) . '"', $args['before_widget']);
} else {
$args['before_widget'] = str_replace('class="', 'class="' . esc_attr($css_classes) . ' ', $args['before_widget']);
}
}
// Output
echo $args['before_widget'];
// Before widget template
// Section template
get_template_part('section-templates/section', 'popular-posts');
// Get section template
echo $args['after_widget'];
// After widget template
}
示例15: test_canonical
/**
* @covers WPSEO_Sitemaps::canonical
*/
public function test_canonical()
{
$url = site_url();
$this->assertNotEmpty(self::$class_instance->canonical($url));
set_query_var('sitemap', 'sitemap_value');
$this->assertFalse(self::$class_instance->canonical($url));
set_query_var('xsl', 'xsl_value');
$this->assertFalse(self::$class_instance->canonical($url));
}