Frage

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.

War es hilfreich?

Lösung

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();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit wordpress.stackexchange
scroll top