繁体   English   中英

如何在 WordPress 中实现这样的目标

[英]How to Achieve Something Like This In WordPress

嘿,我正在尝试创建一个显示特定页面的页面(希望这是有道理的),可能是通过调用他们的帖子 ID 或其他方式。

我想提取页面缩略图/特色图片、页面标题、页面描述,然后是指向该页面的链接。

与此类似的东西。

<ul>
<li>
<?php the_post_thumbnail(); ?>
<h2>Page Title</h2>
<p>Page Description</p>
<a href="#">Link to page</a>
</li>
</ul>

任何帮助将不胜感激,在此先感谢。

更新:目前我有这样的事情。 使用自定义字段来引入描述。 我仍在尝试弄清楚如何仅显示位于名为“Culture”的父页面下的页面。

<?php query_posts('post_type=page'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <?php the_post_thumbnail(); ?>

    <h2><?php the_title(); ?></h2>

    <p>
    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'description', true);
    ?>
    </p>

    <a href="<?php the_permalink(); ?>">More info</a>
    <?php endwhile; endif; ?>    

更新2:解决了。 如果有人感兴趣,请使用以下内容。 从父页面(id = 7)拉入所有子页面,然后是帖子缩略图,然后是页面标题,使用称为描述的自定义字段的描述,最后是永久链接。

希望这可以帮助处于类似情况的任何人。

<?php query_posts('post_type=page&post_parent=7'); ?>
  <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

  <?php the_post_thumbnail('culture-page-listing'); ?>

  <h2><?php the_title(); ?></h2>

  <p>
  <?php
  global $wp_query;
  $postid = $wp_query->post->ID;
  echo get_post_meta($postid, 'description', true);
  ?>
  </p>

  <a href="<?php the_permalink(); ?>">More info</a>
<?php endwhile; endif; ?>

前段时间我在 WP 中写了一个循环,我确信它并不完美,但它基本上做了类似的事情(由类别分隔)。

http://www.kyleboddy.com/2010/10/14/wordpress-code-attachment-category-loop/

<?php
 $areas = array(1 => 'Seattle','East Side & Mercer Island','North Side','South Side');
 $slugs = array(1 => 'seattle-jobs','east-side-and-mercer-island-jobs','north-end-jobs','south-end-and-west-seattle-jobs');
 $i = count($areas);
 $n = 1;

 while ($n <= $i)
 {
     global $post;
     $myposts = get_posts('numberposts=-1&offset=0&category_name=' . $slugs[$n]);
     echo '<div id="imageList">';
     echo '<a name="' . $areas[$n] . '"></a><h2>' . $areas[$n] . '</h2>';
     echo '<table id="ourwork"><tr>';
     $x = 1;

     foreach($myposts as $post)
     {
       setup_postdata($post);

        echo '<td>';
        $args = array(
                'post_type' => 'attachment',
                'numberposts' => '-1',
                'post_status' => null,
                'post_parent' => $post->ID
        );
        $attachments = get_posts($args);

        if ($attachments) {
                    $y = count($attachments);
                    $y--;
                    echo '<a href="' . $post->guid . '">';
                    echo wp_get_attachment_image($id = $attachments[$y]->ID, $size=array(200,133), $icon = false);
                    echo '<strong><br><br>';
                    echo apply_filters('the_title', $attachments[$y]->post_title);
                    echo '</strong></a>';
                    echo '</td>';
                    if ($x == 4)
                    {
                        echo '</tr><tr>';
                        $x = 0;
                    }
                    $x++;
                }
     }
    echo '</tr></table>';
    echo '</div><div class="blog"></div>';
    $n++;
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM