• Resolved navi

    (@naviarora)


    Hello,
    I want show list of all pages in my wordpress blog with ‘page slug’ as title and not the ‘page title’.

    If you didn’t got what I’m saying, then here’s a simple example:
    I have a page with url https://www.website.com/page-slug/ and title ‘Page Title’. If I use <?php wp_list_pages(‘title_li=’); ?> then it will give output:

    I want:

    And i don’t want change page title to slug.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter navi

    (@naviarora)

    Could you please elaborate what arguments to use as per my need ?

    <?php get_pages(); ?>

    <?php
    $mypages = get_pages();
    if( $mypages) echo "<ul>\n";
    foreach($mypages as $page) {
    	$page_link = get_page_link($page->ID);
    	$url = get_site_url() .'/';
    	$page_slug = str_replace($url , '', $page_link );
    	?>
    	<li><a href="<?php echo $page_link; ?>"><?php echo $page_slug; ?></a></li>
    	<?php
    }
    if( $mypages) echo "</ul>\n";
    ?>
    Thread Starter navi

    (@naviarora)

    superb, it worked.
    But can we remove the trailing slash from slug ?
    Currently its giving output like:

    • page-slug/

    I did it myself by adding a line:
    $page_slug = str_replace(‘/’, ”, $page_slug );
    Now the problem is of disabling child pages only.

    Thread Starter navi

    (@naviarora)

    And i don’t want sub pages too ??

    Try:

    <?php
    $page_list = array();
    $mypages = get_pages();
    foreach($mypages as $page) {
        if( !$page->page_parent ) {
            $page_link = substr( get_page_link($page->ID), 0,strlen($page_slug)-1 );
            $url = get_site_url() .'/';
            $page_list[] = str_replace($url , '', $page_link );
        }
    }
    if( $page_list ) echo "<ul>\n";
    foreach($page_list as $list_item) :?>
    <li><?php echo $list_item;?></li>
    <?php endforeach;
    if( $page_list ) echo "</ul>\n";
    ?>

    * Not tested.

    Thread Starter navi

    (@naviarora)

    Sorry, its not working ??
    Giving out all pages (child and parent), i want parent pages only.

    Thread Starter navi

    (@naviarora)

    Is there any solution ?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to show list of pages in template ?’ is closed to new replies.