doucu9677 2013-09-24 09:27
浏览 25
已采纳

在wordpress中获取两次页面数据

I have my theme page.php as:

<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?> >
        <header class="entry-header">
               <div class="hd"><?php the_title(); ?></div>
            <?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
                <div class="video"><?php the_post_thumbnail(); ?></div>
            <?php endif; ?>
            <div class="hd"><?php //the_title(); ?></div>
        </header><!-- .entry-header -->     
        <?php the_content(); ?>
        <?php wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
        <!-- .entry-content -->
        <footer class="entry-meta">
            <?php edit_post_link( __( 'Edit', 'twentythirteen' ), '<span class="edit-link">', '</span>' ); ?>
        </footer><!-- .entry-meta -->
    </article><!-- #post -->
    <?php // comments_template( '', true ); ?>      
<?php endwhile; ?>

And I have made three page in wordpress blog, image and news and i also assigned them category for each. now i have installed php-exec plugin . Now I am writing some php code in page editor to retrieve blog data...

It working fine but it fetching data twice and now got it is becouse of page.php .

So can i have some condition on page.php if i am trying to fetch some data by cotegory then page.php data would not be display...

here is my code which i applied on blog page editor

<?php if (query_posts('cat=63&showposts=5')) : ?>
    <?php while (have_posts()) : the_post();
        // do whatever you want
    ?>
    <div class="gallery_views"> 
        <div class="hd"><?php the_title(); ?></div>
        <?php // get_template_part( 'content', get_post_format() ); ?>
        <?php // cup_post_nav(); ?>
        <?php the_post_thumbnail(); ?>
        <?php comments_template(); ?>
        <b><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></b>
    </div>
    <?php endwhile; ?>
<?php else : ?> 

Thanks in advance..

  • 写回答

1条回答 默认 最新

  • dqba94394 2013-09-24 09:38
    关注
    <?php if (query_posts('cat=63&showposts=5')) : ?>
    <?php while (have_posts()) : the_post();
      // do whatever you want
    ?><div class="gallery_views"> 
     <div class="hd"><?php the_title(); ?></div>
    <?php // get_template_part( 'content', get_post_format() ); ?>
                    <?php // cup_post_nav(); ?>
    <?php the_post_thumbnail(); ?>
                    <?php comments_template(); ?>
    <b><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></div>
    <?php
    break;
    endwhile;
    ?>
    <?php else : ?>
    

    Add a break in your while, it'll stop after the first loop.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式