dongwei6457 2011-10-16 16:53
浏览 41
已采纳

wordpress自定义帖子模板中的语法错误,意外的T_DOUBLE_ARROW

I'm having some problems with the following code:

<?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(); 
?>

I get *'syntax error, unexpected T_DOUBLE_ARROW'*

I've used similar code before without problems so I'm a touch mystified.

For clarity the remainder of the template looks like this:-

<?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].'&amp;w=960&amp;h=250&amp;zc=1&amp;q=100&amp;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(' &#183; ', '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();?>
  • 写回答

2条回答 默认 最新

  • dongtan8979 2011-10-16 17:01
    关注

    I don't know much about wordpress, but it seems like that you're trying to pass an array and you forgot to pass it as an array

    Try changing:

    $wp_query->query('post_type' => 'news','posts_per_page='.$gogo_blog_text_no_posts.'&paged='.$paged);
    

    To:

    $wp_query->query(array('post_type' => 'news','posts_per_page='.$gogo_blog_text_no_posts.'&paged='.$paged));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 被蓝屏搞吐了,有偿求帮解答,Ai回复直接拉黑
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角