WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Problem putting sub-pages in the parent-page (2 posts)

  1. MASSERRA
    Member
    Posted 1 year ago #

    Hello everyone!

    I am having a strange problem. It isn't easy to describe, but I'll do my best.
    So, first, I am trying to create a template that writes inside a parent-page some of its sub-pages (or child-page's) content. Only the sub-page title and its featured image.

    This is the code:

    <?php
    /**
     *	Template Name: Projects
     */
    ?>
    
    <?php get_header(); ?>
    
    		<div id="primary">
    			<div id="content" role="main">
    
    					<?php $subpages = new WP_Query("post_parent=$pageid&post_type='page'&orderby=title&order=DESC");
    					if($subpages->have_posts()) : while($subpages->have_posts()) : $subpages->the_post(); ?>
    						<div class="post">
    							<?php echo '<h3><a href="' . the_permalink() . '">' . get_the_title() . '</a></h3>'; ?>
    							<div class="entry">
    								<?php echo the_permalink(); ?> <!-- this was not here, it was added to test the permalink, like I'll explain later-->
    								<?php the_post_thumbnail( 'single-post-thumbnail' ); ?>
    							</div>
    						</div>
    					<?php endwhile; endif; ?>
    
    			</div><!-- #content -->
    		</div><!-- #primary -->
    
    <?php get_footer(); ?>

    So, what's going on, and you're going to find it really weird, is that this line:

    <?php echo '<h3><a href="' . the_permalink() . '">' . get_the_title() . '</a></h3>'; ?>

    prints this between the line with the div class post and the div class entry:

    <div class="post">
    http://cannatafernandes.com/wp/?page_id=23&lang=pt
    <h3><a href="">Projecto 1</a></h3>
    <div class="entry">

    So, not only it does not put the permalink in between the href="" as it also links to the parent-page (actual page), without any URL inside the href"", don't know how... But if I take the permalink() of that line it prints well...

    Again, all I'm trying to do is to put the title of a subpage linking to its permalink, accompanied with its featured image, inside the parent-page...

    Thank you in advance to anyone that tries to solve this... ;)

  2. dariocanata
    Member
    Posted 1 year ago #

    Good luck.....

Topic Closed

This topic has been closed to new replies.

About this Topic