English 中文(简体)
php wordpress 通过 ID 获得文章, 并在每页上制作专栏
原标题:php wordpress get post by id and make featured section on every page

最近我刚刚刚刚对一个功能化部分进行编码, 它实际上将拉动在阵列中指定位置的柱子 。 这是代码

<div class="container_24">
<ul id="featured_posts" class="grid_24">

<?php $thePostIdArray = array("13968","14293", "15018", "15512"); ?>
<?php $limit = 4 ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); $counter++; ?>
<?php if ( $counter < $limit + 1 ): ?>

<?php $post_id = $thePostIdArray[$counter-1]; ?>
<?php $queried_post = get_post($post_id); ?>
 <li class="featured_post">
    <div class="featured_thumbnail"> <a href="<?php echo get_permalink( $post_id ); ?>"><img width="55" height="55" src="<?php echo img_feature($post_id) ?>" class="attachment-featured-small wp-post-image" alt="<?php echo $queried_post->post_title; ?>"></a></div>
    <div class="featured_title">
      <h2><a href="<?php echo get_permalink( $post_id ); ?>"><?php echo $queried_post->post_title; ?></a></h2>
    </div>
  </li>

<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>

</ul>
</div>

现在,这个代码在 home , archive 和任何有 post 环页的页面上完美运作,并按其设想显示 4 显示文章内容,但是它没有显示在任何其他没有 post single.php contact page 的页面上,也没有显示“code>4 /code> 环页的问题,以及任何其他像没有邮单页的页面的问题。

我不知道我是否做错了什么,我在 header 上包括了这个内容,它会显示给包括 header 在内的所有页面, 问题只是显示第一个, 而不是其他的就像循环只进行一次停止。

如果我做错了什么 请指出我

谢谢 谢谢

最佳回答

像下面一样使用每个圆环。

<div class="container_24">
<ul id="featured_posts" class="grid_24">

<?php $thePostIdArray = array("13968","14293", "15018", "15512"); ?>
<?php foreach ($thePostIdArray as $post_id) : ?>
    <?php $queried_post = get_post($post_id); ?>
     <li class="featured_post">
        <div class="featured_thumbnail"> <a href="<?php echo get_permalink( $post_id ); ?>"><img width="55" height="55" src="<?php echo img_feature($post_id) ?>" class="attachment-featured-small wp-post-image" alt="<?php echo $queried_post->post_title; ?>"></a></div>
    <div class="featured_title">
        <h2><a href="<?php echo get_permalink( $post_id ); ?>"><?php echo $queried_post->post_title; ?></a></h2>
    </div>
  </li>
 <?php endforeach; ?>

</ul>
</div>
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签