Link to a custom page without a permalink?

admin2025-06-05  2

I am working on a custom Wordpress theme, I have the index.php setup for the Home view, I'd like to create another page to list all the blog posts, I am familiar with the loop, I just want to know how to link to the new page properly. Here's what I am using

<a href="<?php echo get_bloginfo('template_directory');?>/blogs.php">Blog Listing</a>

However when I get redirect to http://localhost/wordpress/wp-content/themes/final/blogs.php I get atal error: Uncaught Error: Call to undefined function the_title() in, I am guessing it's interpreting the blogs.php on the face level and not passing the wordpress context. A little help is required.

I am working on a custom Wordpress theme, I have the index.php setup for the Home view, I'd like to create another page to list all the blog posts, I am familiar with the loop, I just want to know how to link to the new page properly. Here's what I am using

<a href="<?php echo get_bloginfo('template_directory');?>/blogs.php">Blog Listing</a>

However when I get redirect to http://localhost/wordpress/wp-content/themes/final/blogs.php I get atal error: Uncaught Error: Call to undefined function the_title() in, I am guessing it's interpreting the blogs.php on the face level and not passing the wordpress context. A little help is required.

Share Improve this question asked Dec 13, 2018 at 18:44 Sahil ShuklaSahil Shukla 36 bronze badges 1
  • Hello Sahil and welcome to WPSE. You are correct. WordPress is actually not running when you attempt to load a template file directly. Let the CMS handle that. From your question, it seems you want a static front page and a blog home page separately. I would restore the index.php file to its original state and read this: codex.wordpress/Creating_a_Static_Front_Page – jdm2112 Commented Dec 13, 2018 at 19:09
Add a comment  | 

1 Answer 1

Reset to default 0

First of all thank you to @jdm2112 for such a quick response. I was able to serve a custom page by creating a page from inside the Wordpress admin panel to get a permalink wordpress.live/blogs. After that I setup my page.php to loop through all the posts using the following code

<?php get_header();?>
        <?php $wpdb = new WP_Query(array(
            'post_type'=>'post',
            'post_status' => 'published',
            'posts_per_page' => -1));

            if($wpdb->have_posts()):
                while($wpdb->have_posts()):
                    $wpdb->the_post();?>
            <?php
            // This calls the blogs.php that has the custom layout for blog listing.
            get_template_part('blogs');
                // echo the_title();
                endwhile;
            endif;
            ?>
<?php get_footer();?>

simply calling the_title() from blogs.php prints out the all the posts title. Blogs.php

 the_title();
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749094081a316313.html

最新回复(0)