开发者

How to Achieve Something Like This In WordPress

开发者 https://www.devze.com 2023-03-09 16:09 出处:网络
Hey there, I\'m trying to create a page showing specific pages (hope that makes sense), probably by calling their post ID\'s or something.

Hey there, I'm trying to create a page showing specific pages (hope that makes sense), probably by calling their post ID's or something.

I want to pull in the page thumbnail/featured image, the page title, the page's description, and then a link to that page.

Something along the lines of this.

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

Any help will be appreciated, thanks in advance.

UPDATE: At the moment I've got something like this. Using a custom field to bring in the description. I'm still trying to work out how I'd only show pages that are under a parent page called "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; ?>    

UPDATE 2: Solved it! Used the following if anyone's interested. Pulled in all subpages from parent page (id=7). Then the post thumbnail, followed by the page title, description using a custom field called description and finally the permalink.

Hope this helps anyone in a similar situation.

<开发者_如何学编程?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; ?>


I wrote a loop in WP some time ago which I'm sure isn't perfect, but it did basically something like that (delimited by categories).

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++;
  }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号