0

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.

  • 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.org/Creating_a_Static_Front_Page – jdm2112 Dec 13 '18 at 19:09
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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.