I’m quite new to wordpress and php in generall and am currently building my first real theme.
On one of my sites I show various projects which are child-pages of the overview-page
On that page I show preview-Images and then on hover I add a div with a background-color and blend in the project-Name and a button to get to the project (it’s sort of a hover in a hover). But that isnt my real problem, most of that actually works. But I can’t seem to figure out how to actually link to the displayed child pages. It allready gets the right thumbnails and everything, just the link that uses the same function doesnt seem to work.
Can one of you tell me how I modify my code to link the h6 to its child page?
Would be a huge help.
Thanks a lot in advance.
<div id="mainContent">
<div id="primary">
<p>
<?php the_content(); ?>
</p>
<?php
$args = array(
'child_of' => get_the_ID(),
'sort_order' => 'ASC'
);
$pages = get_pages($args);
// var_dump($pages);
foreach($pages as $page) {
?>
<div class="moreProjectsImages left">
<div class="projectHover">
<h5 class="title center">
<?php echo $page->post_title ; ?>
</h5>
<a href="<?php get_permalink($page->ID) ?>" class="btnDoubleHover">
<h6 class="center">
View Project
</h6>
</a>
</div>
<img src="<?php echo '<a href="'.get_permalink($page->ID) . '">'.get_the_post_thumbnail($page->ID, array(285,175)).'</a>'; ?>" />
</div>
<?php
}
?>
</div>
</div>
The function
get_permalink()
only returns the result, you need to echo it which you are doing for the thumb but not for the URL. Also there is a function specifically for page linksget_page_link()
.Correct code to get the link: