我在使用以下代码时遇到了一些问题:
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('post_type' => 'news','posts_per_page='.$gogo_blog_text_no_posts.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
我得到''语法错误,意外的T_DOUBLE_ARROW'*
我之前使用过类似的代码而没有任何问题,所以我觉得很神秘。
为清楚起见,模板的其余部分如下所示: -
<?php
/*
Template Name: In The News page
*/
?>
<?php get_header(); ?>
<?php
$gogo_blog_text_headline = get_post_meta($post->ID, 'gogo_blog_text_headline', true);
$gogo_select_blog_sidebar_position = get_post_meta($post->ID, 'gogo_select_blog_sidebar_position', true);
$gogo_blog_link_text = get_post_meta($post->ID, 'gogo_blog_link_text', true);
$gogo_blog_link_url = get_post_meta($post->ID, 'gogo_blog_link_url', true);
$gogo_blog_text_no_posts = get_post_meta($post->ID, 'gogo_blog_text_no_posts', true);
?>
<?php if($gogo_blog_text_headline) { ?>
<!-- Begin Motto -->
<div class="motto-meta">
<h1><?php echo $gogo_blog_text_headline; ?></h1>
</div>
<!-- End Motto -->
<?php } ?>
<!-- Begin Page image -->
<?php if (has_post_thumbnail($post->ID)) { ?>
<?php $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large');
echo '<div class="header-image"><img src="'.get_template_directory_uri().'/lib/includes/timthumb.php?src='.$thumbnail[0].'&w=960&h=250&zc=1&q=100&s=1" alt="'.get_the_title().'" /></div>';?>
<?php } ?>
<!-- End Page image -->
</div>
<!-- End Header -->
<!-- Begin main wrap (it ends in footer.php) -->
<div class="wrap wide">
<div class="main-content-holder">
<?php if($gogo_select_blog_sidebar_position=='right-sidebar-blog-template') { ?>
<!--Left content area-->
<div class="left-content left">
<?php } else { ?>
<div class="left-content right">
<?php } ?>
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('post_type' => 'news','posts_per_page='.$gogo_blog_text_no_posts.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<!--Begin post content-->
<?php
// The following determines what the post format is and shows the correct file accordingly
$format = get_post_format();
get_template_part( '/lib/includes/post-formats/'.$format );
if($format == '')
get_template_part( '/lib/includes/post-formats/standard' );
?>
<!--End post content-->
<?php endwhile; ?>
<!--End left content-->
<!--Pagination -->
<!--<?php posts_nav_link(' · ', 'previous page', 'next page'); ?>-->
<?php if (function_exists("pagination")) {pagination($additional_loop->max_num_pages);} ?>
<!--End pagination -->
<?php $wp_query = null; $wp_query = $temp;?>
</div>
<!--End left content area-->
<?php if($gogo_select_blog_sidebar_position=='right-sidebar-blog-template') { ?>
<!-- Right content -->
<div class="right-content right">
<?php } else { ?>
<div class="right-content left">
<?php } ?>
<?php get_sidebar('blog'); ?>
</div>
<!-- End Right content -->
</div>
<?php get_footer();?>
答案 0 :(得分:2)
我对wordpress知之甚少,但看起来你正试图传递一个数组但是你忘了把它作为一个数组传递
尝试更改:
$wp_query->query('post_type' => 'news','posts_per_page='.$gogo_blog_text_no_posts.'&paged='.$paged);
要:
$wp_query->query(array('post_type' => 'news','posts_per_page='.$gogo_blog_text_no_posts.'&paged='.$paged));
答案 1 :(得分:0)
你的意思
$wp_query->query('post_type=news&posts_per_page='.$gogo_blog_text_no_posts.'&paged='.$paged);
?双箭头在那里没有任何意义。