php - Wordpress child pages not working

admin2025-01-07  4

I am creating a wordpress CMS and I have added multiple pages under one parent page. I am generating the links for all the child pages of a page and then when user clicks on the links, they should be able to open the child page. How ever when I click on the links, the index page is opened and no child page content is displayed. May be it is due to the use of the .htaccess file. I dont have any knowledge of htaccess. Any help?

<?php
            $pages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc' ) );

            foreach ($pages as $page) {
            ?>

                <div class="contentarea">
                <div class="leftside"><img alt="" src=".jpg" /></div>
                <div class="rightside">
                <h2><?php echo $page->post_title; ?></h2>
                <?php echo substr(strip_tags($page->post_content),0,50); ?>

                <a href="<?php echo get_post_permalink($page->ID); ?>">Read More...</a>

                </div>
                </div>

            <?php

                }
            ?>  

.htaccess

 # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

# END WordPress

I am creating a wordpress CMS and I have added multiple pages under one parent page. I am generating the links for all the child pages of a page and then when user clicks on the links, they should be able to open the child page. How ever when I click on the links, the index page is opened and no child page content is displayed. May be it is due to the use of the .htaccess file. I dont have any knowledge of htaccess. Any help?

<?php
            $pages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc' ) );

            foreach ($pages as $page) {
            ?>

                <div class="contentarea">
                <div class="leftside"><img alt="" src="http://zom.jtechsolutions.co/wp-content/themes/zone/images/pic_1.jpg" /></div>
                <div class="rightside">
                <h2><?php echo $page->post_title; ?></h2>
                <?php echo substr(strip_tags($page->post_content),0,50); ?>

                <a href="<?php echo get_post_permalink($page->ID); ?>">Read More...</a>

                </div>
                </div>

            <?php

                }
            ?>  

.htaccess

 # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

# END WordPress
Share Improve this question asked Feb 27, 2013 at 23:24 prakashchhetriprakashchhetri 1234 bronze badges 5
  • Can you post a link to the problem page? – s_ha_dum Commented Feb 27, 2013 at 23:44
  • @s_ha_dum zom.jtechsolutions.co/services – prakashchhetri Commented Feb 27, 2013 at 23:53
  • Those links look right. Unfortunately your theme is not using body_class so I can't tell what template is loading. – s_ha_dum Commented Feb 28, 2013 at 0:16
  • What's your permalink structure? – jfacemyer Commented Feb 28, 2013 at 4:01
  • The clue will be inspecting the URLs as HTML then copy pasting them into a browser. If they look well-formed but go to the wrong page there’s a permalink problem, if the links are not well formed there’s a PHP problem. If the latter then print_r everything in sight. – Chris Pink Commented Mar 24, 2021 at 20:25
Add a comment  | 

1 Answer 1

Reset to default 0

According to the codex, get_post_permalink applies to custom post types. I don't think you are using a custom post type, right?

Instead, try get_page_link( $page->ID )

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736256199a342.html

最新回复(0)