• Resolved downfast

    (@downfast)


    How do i make it so that my thumb links to its post?

    This is the code I am using:

    echo get_the_post_thumbnail($page->ID);

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Is this inside the Loop? If so, why are you using $page->ID?

    Thread Starter downfast

    (@downfast)

    yes this is the whole code actually

    <ul>
    <?php
    $parent = 6;
    $args=array(
    'child_of' => $parent
    );
    $pages = get_pages($args);
    shuffle($pages);
    if ($pages) {
    $pageids = array();
    foreach ($pages as $page) {
    $pageids[]= $page->ID;
    }
    echo get_the_post_thumbnail($page->ID);
    }
    ?>
    </ul>

    Thread Starter downfast

    (@downfast)

    it is, this is the full code actually:

    <ul>
    <?php
    $parent = 6;
    $args=array(
    'child_of' => $parent
    );
    $pages = get_pages($args);
    shuffle($pages);
    if ($pages) {
    $pageids = array();
    foreach ($pages as $page) {
    $pageids[]= $page->ID;
    }
    echo get_the_post_thumbnail($page->ID);
    }
    ?>
    </ul>

    ideally i would like to show the post title of that thumb as well and both the title and the thumb to be a link to its post

    How about:

    <ul>
    <?php
    $parent = 6;
    $args=array(
    	'child_of' => $parent
    );
    $pages = get_pages($args);
    shuffle($pages);
    if ($pages) {
    	foreach ($pages as $page) :?>
    	<li><a href="<?php echo get_page_link($page->ID)"><?php echo $page->post_title; ?> <?php get_the_post_thumbnail($page->ID);?></a></li>
    	<?php endforeach;
    }
    ?>
    </ul>
    Thread Starter downfast

    (@downfast)

    did you forget to close any tags? gives me an error ??

    Thread Starter downfast

    (@downfast)

    Fixed.

    $parent = 6;
    $args=array(
    'child_of' => $parent
    );
    $pages = get_pages($args);
    shuffle($pages);
    if ($pages) {
    $pageids = array();
    foreach ($pages as $page) {
    $pageids[]= $page->ID;
    $title = get_the_title($page->ID);
    $link = get_page_link($page->ID);
    }
    echo get_the_post_thumbnail($page->ID);
    echo "<a href='$link'>$title</a>";
    }
    ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘post_thumb to link to its post?’ is closed to new replies.