admin管理员组文章数量:1130349
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.
- 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
1 Answer
Reset to default 0First 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();
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.
- 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
1 Answer
Reset to default 0First 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();
本文标签: Link to a custom page without a permalink
版权声明:本文标题:Link to a custom page without a permalink? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749094056a2314974.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论