DISPLAY PAGES

How to Display Created Pages in Different Ways

Creating your pages with LPagery is the one thing, displaying them natively in your website the other. There are multiple ways of displaying pages you created. We will go through some of them here starting with no code variations we directly built into LPagery do display pages and then go over some code examples to show you how to completely customize the way you display your created pages on your website.

Table of Contents

1. Display Links To The Next And Previous Pages

When creating multiple pages it can sometimes be useful to dynamically link to the next and previous pages of a page. For example if you want your users to be able to navigate through all your existing locations for a store, you can use this to insert links at the bottom of each page to dynamically set these links. The order of the pages is the one from your source file. 

How to Achieve This:

For this you would need to create your buttons on your template page and insert

[lpagery_link position="NEXT" title="" circle=true target="_blank"]

and

[lpagery_link position="PREVIOUS" title="" circle=true target="_blank"]

into the “Service in Location 1” and “Service in Location 3” texts from the screenshot.  You can find a detailed guide on all available interlinking attributes here:

How to Interlink Pages

2. Display List of All Created Pages

If you want to just display a complete list of all your pages you created in one batch, you can use the built in shortcode functionality of LPagery. This lets you just copy a shortcode for a batch of created pages and then displays a list of all created pages of that batch and also links to each page. This is an easy way to create fast interlinks between your pages so they will get recognized faster by search engines like Google.

Premium Features
Premium Features Used in This Example
Manage Pages

Let’s you manage your pages after they’ve been created and also let’s you get a shortcode for the created pages to display them easily.

Step 1: Go to "Manage" in LPagery Pro and open the settings

Step 2: Click "Copy Shortcode"

Step 3: Paste the shortcode where you want to display the list

3. Display Created Pages Using Elementor (And other page builders)

When you are using a pagebuilder like Elementor, where you can create layouts for posts and pages, you can easily create an overview of your created pages by adding a category to the pages and then setting the display condition of your widget to the category of the created pages. 

Premium Features
Premium Features Used in This Example
Add Categories and Parent Pages

Let’s you manage your pages after they’ve been created and also let’s you get a shortcode for the created pages to display them easily.

Step 1: Add categories to your pages

Add a category to the pages using the LPagery dashboard.

Step 2: Create your Elementor widget

Choose the “Posts” widget from Elementor:

Step 3: Set the query to the category

  1. Choose your page type in “Source”
  2. Set the term to your category of the pages you want to display.

4. Display Created Pages Using Custom Code

When none of the above ways of displaying your pages fits your needs, you can always use custom code to display the created pages. For this you will need:

  1. Add custom code in a custom plugin or your functions.php
  2. A category assigned to the pages you want to display 

Below we have listed an examples you can copy, adjust the terms of the query and paste it into your plugin or functions.php file. 

Check this post to see how you can easily create a custom plugin ->

 

Premium Features
Premium Features Used in This Example
Add Categories and Parent Pages

Let’s you manage your pages after they’ve been created and also let’s you get a shortcode for the created pages to display them easily.

Example: Alphabetical display of location pages

In this example the pages of the category “city” gets display in an alphabetical order and also each new letter gets highlighted to create a nice overview of all of your locations.

				
					<?php
/*
Plugin Name: Display Pages Sorted by Category
Description: A plugin to display pages sorted by category and in alphabetical order.
Version: 0.1
Author: Your Name
*/

function display_sorted_pages_by_category($atts) {
    // Shortcode attributes with no default values
    $atts = shortcode_atts(
        array(
            'slug' => '',  // No default value, user must provide the slug
        ), 
        $atts, 
        'sorted_pages_by_category'
    );

    // Check if a slug is provided
    if (empty($atts['slug'])) {
        return '<p>No slug provided. Please add a slug.</p>';
    }

    // Query arguments to get pages from the specified category
    $args = array(
        'post_type' => 'page',  // Query only pages (not posts)
        'posts_per_page' => -1,  // Query all pages, no limit
        'orderby' => 'title',  // Sort by title
        'order' => 'ASC',  // Sort in ascending order (alphabetical)
        'tax_query' => array(  // Taxonomy query to get pages from a specific category
            array(
                'taxonomy' => 'category',  // Category taxonomy
                'field' => 'slug',  // Use the slug (URL-friendly name) of the category
                'terms' => $atts['slug'], // Use the provided slug
            ),
        ),
    );

    // Query the pages based on the arguments defined above
    $pages = new WP_Query($args);

    // Check if pages were found
    if ($pages->have_posts()) {
        // Create an array to store titles and links
        $sorted_pages = array();

        // Loop through the found pages
        while ($pages->have_posts()) {
            $pages->the_post();
            $title = get_the_title();  // Get the page title

            // Store the original title and permalink (URL) of the page in the array
            $sorted_pages[$title] = get_permalink();
        }

        // Sort the array by the titles (alphabetically)
        ksort($sorted_pages);

        // Start output buffering (to collect HTML)
        ob_start();

        // Add CSS styles for layout and design
        echo '<style>
            .sorted-pages {
                margin: 20px auto;
                max-width: 800px;
            }
            .sorted-pages .letter-section {
                margin-bottom: 20px;
            }
            .sorted-pages .letter-indicator {
                font-size: 24px;
                font-weight: bold;
                color: #F5A623;
                margin-bottom: 10px;
            }
            .sorted-pages ul {
                list-style-type: none;
                padding: 0;
                margin: 0;
            }
            .sorted-pages ul li {
                margin: 5px 0;
                padding: 10px;
                box-sizing: border-box;
                width: 100%;
            }
            .sorted-pages ul li a {
                text-decoration: none;
                color: #333;
                font-size: 16px;
            }
        </style>';

        $current_letter = '';  // Current letter (for comparison)

        echo '<div class="sorted-pages">';

        // Loop through the sorted pages
        foreach ($sorted_pages as $title => $permalink) {
            $first_letter = strtoupper($title[0]);  // First letter of the title

            // Display a new letter heading if the first letter changes
            if ($first_letter !== $current_letter) {
                if ($current_letter !== '') {
                    echo '</ul></div>';  // Close the previous list if present
                }
                $current_letter = $first_letter;
                echo '<div class="letter-section">';
                echo '<div class="letter-indicator">' . $current_letter . '</div>';  // Display letter indicator
                echo '<ul>';
            }

            // Display the title with a link to the page
            echo '<li><a href="' . esc_url($permalink) . '">' . esc_html($title) . '</a></li>';
        }

        // Close the last list and section
        echo '</ul></div>';

        echo '</div>';

        // Reset post data (very important)
        wp_reset_postdata();

        // Return the collected HTML
        return ob_get_clean();
    } else {
        // If no pages were found, display a message
        return '<p>No pages found for slug "' . esc_html($atts['slug']) . '"</p>';
    }
}

// Register shortcode to allow the code to be used within content
add_shortcode('custom_lp_sorted_pages_by_category', 'display_sorted_pages_by_category');

				
			

Then you can use this shortcode to display the pages of the category which you define in the shortcode in the “slug” parameter.

				
					[custom_lp_sorted_pages_by_category slug="category-slug"]
				
			

Variation: Remove parts of the title to only display the city

If your page title is “Window Cleaning in City” but you don’t want to have the “Window Cleaning in” part displayed in the overview, you can simply add this line to the php code

				
					            // Remove specific placeholder text from the title to sort by actual name
            $clean_title = str_replace('Window Cleaning in ', '', $title);  // **This line alters the title**

            // Store the cleaned title and permalink (URL) of the page in the array
            $sorted_pages[$clean_title] = get_permalink();  // **This line uses the modified title**

				
			

The complete code then looks like this:

				
					<?php
/*
Plugin Name: Display Pages Sorted by Category
Description: A plugin to display pages sorted by category and in alphabetical order.
Version: 0.1
Author: Your Name
*/

function display_sorted_pages_by_category($atts) {
    // Shortcode attributes with no default values
    $atts = shortcode_atts(
        array(
            'slug' => '',  // No default value, user must provide the slug
        ), 
        $atts, 
        'sorted_pages_by_category'
    );

    // Check if a slug is provided
    if (empty($atts['slug'])) {
        return '<p>No slug provided. Please add a slug.</p>';
    }

    // Query arguments to get pages from the specified category
    $args = array(
        'post_type' => 'page',  // Query only pages (not posts)
        'posts_per_page' => -1,  // Query all pages, no limit
        'orderby' => 'title',  // Sort by title
        'order' => 'ASC',  // Sort in ascending order (alphabetical)
        'tax_query' => array(  // Taxonomy query to get pages from a specific category
            array(
                'taxonomy' => 'category',  // Category taxonomy
                'field' => 'slug',  // Use the slug (URL-friendly name) of the category
                'terms' => $atts['slug'], // Use the provided slug
            ),
        ),
    );

    // Query the pages based on the arguments defined above
    $pages = new WP_Query($args);

    // Check if pages were found
    if ($pages->have_posts()) {
        // Create an array to store titles and links
        $sorted_pages = array();

        // Loop through the found pages
        while ($pages->have_posts()) {
            $pages->the_post();
            $title = get_the_title();  // Get the page title

            // Remove placeholder text from the title to sort by the actual name
            $clean_title = str_replace('Window Cleaning in ', '', $title);

            // Store the cleaned title and permalink (URL) of the page in the array
            $sorted_pages[$clean_title] = get_permalink();
        }

        // Sort the array by the cleaned titles (alphabetically)
        ksort($sorted_pages);

        // Start output buffering (to collect HTML)
        ob_start();

        // Add CSS styles for layout and design
        echo '<style>
            .sorted-pages {
                margin: 20px auto;
                max-width: 800px;
            }
            .sorted-pages .letter-section {
                margin-bottom: 20px;
            }
            .sorted-pages .letter-indicator {
                font-size: 24px;
                font-weight: bold;
                color: #F5A623;
                margin-bottom: 10px;
            }
            .sorted-pages ul {
                list-style-type: none;
                padding: 0;
                margin: 0;
            }
            .sorted-pages ul li {
                margin: 5px 0;
                padding: 10px;
                box-sizing: border-box;
                width: 100%;
            }
            .sorted-pages ul li a {
                text-decoration: none;
                color: #333;
                font-size: 16px;
            }
        </style>';

        $current_letter = '';  // Current letter (for comparison)

        echo '<div class="sorted-pages">';

        // Loop through the sorted pages
        foreach ($sorted_pages as $clean_title => $permalink) {
            $first_letter = strtoupper($clean_title[0]);  // First letter of the cleaned title

            // Display a new letter heading if the first letter changes
            if ($first_letter !== $current_letter) {
                if ($current_letter !== '') {
                    echo '</ul></div>';  // Close the previous list if present
                }
                $current_letter = $first_letter;
                echo '<div class="letter-section">';
                echo '<div class="letter-indicator">' . $current_letter . '</div>';  // Display letter indicator
                echo '<ul>';
            }

            // Display the title with a link to the page
            echo '<li><a href="' . esc_url($permalink) . '">' . esc_html($clean_title) . '</a></li>';
        }

        // Close the last list and section
        echo '</ul></div>';

        echo '</div>';

        // Reset post data (very important)
        wp_reset_postdata();

        // Return the collected HTML
        return ob_get_clean();
    } else {
        // If no pages were found, display a message
        return '<p>No pages found for slug "' . esc_html($atts['slug']) . '"</p>';
    }
}

// Register shortcode to allow the code to be used within content
add_shortcode('custom_lp_sorted_pages_by_category', 'display_sorted_pages_by_category');

				
			
Pro Feature

When to Use This Feature

Use Examples