URL for all my blog posts?
-
Hi there,
This might be a little bit confusing so I’m going to try to lay it out as linearly as possible.
I’m using the theme minimatica for which there are two default home pages — a gallery view and a standard blog view. This is an option in Apperance > Theme Options.
The gallery view is currently enabled on my site: https://www.kylechadha.com/.
The standard blog view looks just like a category page, but contains all blog posts published (ie, the page is structured like the following but is not specific to any category: https://www.kylechadha.com/category/tech/)
I want to use the gallery view as my home page, and then link to the standard blog view in the navigation, but I can’t figure out how to do this. In other words, when people click on the word ‘Blog’ on my home page, I want it to go to the alternate view where all my blog posts are listed.
Currently in “Settings > Reading” I have my front page set to “Your latest posts.” If I change it to static and try to create a posts page, both the home page and the posts page become the same. This is not what I want. It still always displays the gallery view or the blog view, whereas I want one to link to the other.
Does any one have any thoughts or advice on how to do this? The gallery view of the theme only shows 4 posts, and I would like a dedicated “Blog” page that shows all the posts. I would hope there would just be a default URL for blog posts (like there is for categories, archive, etc.), but quite a bit of googling has yielded no results.
Many thanks in advance. Any help would be much appreciated!
-
If you are familiar with WP template files and WP functions, you can create a new page template with code in it to list all blog posts and assign it to a newly created page, say ‘Blogs’. So you can keep your front page as the current gallery page and can link the menu Blog to above created page. See this
Hrmm… I don’t really have any experience doing this, but I took a stab at it based on the link you provided. I made a copy of ‘home.php’ and renamed it ‘blog.php’, and edited out the if/else condition where it seemed to be deciding between the two views. I then added the “Template Name” text in a comment. I created a page named ‘Blog’ and set the custom template as ‘Blog Page’ … but, alas, it doesn’t seem to be working:
This is the code in ‘blog.php’:
<?php /* * Template Name: Blog Page * Description: Custom Blog Page by muah, Kyle Chadha. */ get_header(); ?> <div id="container"> <?php get_template_part( 'loop', 'index' ); ?> <?php get_sidebar(); ?> <div class="clear"></div> </div><!-- #container --> <?php get_footer(); ?>
Originally, home.php had:
<?php /** * Template to display the default posts page * * @package WordPress * @subpackage Minimatica * @since Minimatica 1.0 */ get_header(); ?> <?php if( 'gallery' == minimatica_get_option( 'homepage_view' ) ) : ?> <div id="slider"> <?php get_template_part( 'loop', 'slider' ); ?> </div><!-- #slider --> <?php else : ?> <div id="container"> <?php get_template_part( 'loop', 'index' ); ?> <?php get_sidebar(); ?> <div class="clear"></div> </div><!-- #container --> <?php endif; ?> <?php get_footer(); ?>
Any thoughts on what I’m doing wrong?
Thanks in advance.
Can you try to paste code from category.php to your custom template. Please don’t remove the Template name, description etc of your custom template. Just paste the code only.
The black bar came back, making the blog page look more normal — but it still doesn’t load the posts. https://www.kylechadha.com/blog/
To clarify, I should copy all the code from category.php and overwrite everything in blog.php besides the comment at the top?
This is the code I have in blog.php now:
get_header(); ?> <?php if( ( 'gallery' == minimatica_get_option( 'category_view' ) ) && ( get_query_var( 'cat' ) != minimatica_get_option( 'blog_category' ) ) ) : ?> <div id="slider"> <?php get_template_part( 'loop', 'slider' ); ?> </div><!-- #slider --> <?php else : ?> <div class="title-container"> <h1 class="page-title"><?php single_cat_title(); ?></h1> </div><!-- .title-container --> <div id="container"> <?php get_template_part( 'loop', 'category' ); ?> <?php get_sidebar(); ?> <div class="clear"></div> </div><!-- #container --> <?php endif; ?> <?php get_footer(); ?>
Apologies, this is the code I have:
<?php /* * Template Name: Blog Page * Description: Custom Blog Page by muah, Kyle Chadha. */ get_header(); ?> <?php if( ( 'gallery' == minimatica_get_option( 'category_view' ) ) && ( get_query_var( 'cat' ) != minimatica_get_option( 'blog_category' ) ) ) : ?> <div id="slider"> <?php get_template_part( 'loop', 'slider' ); ?> </div><!-- #slider --> <?php else : ?> <div class="title-container"> <h1 class="page-title"><?php single_cat_title(); ?></h1> </div><!-- .title-container --> <div id="container"> <?php get_template_part( 'loop', 'category' ); ?> <?php get_sidebar(); ?> <div class="clear"></div> </div><!-- #container --> <?php endif; ?> <?php get_footer(); ?>
try this code in your template.
<?php /* * Template Name: Blog Page * Description: Custom Blog Page by muah, Kyle Chadha. */ get_header(); ?> <div class="title-container"> <h1 class="page-title"><?php the_title(); ?></h1> </div><!-- .title-container --> <div id="container"> <?php global $post; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'posts_per_page' => 10, 'paged' =>$paged, 'post_type' => 'post', 'order' => 'DESC', 'orderby' => 'post_date' ); query_posts( $args ); ?> <?php get_template_part( 'loop', 'index' ); ?> <?php get_sidebar(); ?> <div class="clear"></div> </div><!-- #container --> <?php get_footer(); ?>
Getting very close! Only the formatting is off now.
Can see the difference here:
https://www.kylechadha.com/blog/
https://www.kylechadha.com/2013/Can you share the codes in loop.php ?
<?php /** * The Main Loop * * Used as fallback if no specific loop file found * * @package WordPress * @subpackage Minimatica * @since Minimatica 1.0 */ ?> <?php if( have_posts() ) : ?> <div id="content" role="main"> <?php while( have_posts() ) : the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <header class="entry-header"> <?php if( has_post_thumbnail() ) : ?> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"> <?php the_post_thumbnail( 'homepage-thumb' ); ?> </a> <?php endif; ?> <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php the_title(); ?></a></h2> <aside class="entry-meta<?php if( has_post_thumbnail() ) : ?> folded<?php endif; ?>"> <?php _e( 'By', 'minimatica' ); ?> <?php the_author_posts_link(); ?> <?php _e( 'on', 'minimatica' ); ?> <time datetime="<?php the_time( 'Y-m-d' ); ?>"><?php the_time( get_option( 'date_format' ) ); ?></time> </aside><!-- .entry-meta --> </header><!-- .entry-header --> <section class="entry-summary"> <?php the_excerpt(); ?> </section><!-- .entry-summary --> <footer class="entry-footer"> <a class="more-link" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php echo __( 'Continue reading', 'minimatica' ) . ' →'; ?></a> </footer><!-- entry-footer --> </article><!-- .post --> <?php endwhile; ?> <?php if ( $wp_query->max_num_pages > 1 ) : ?> <div id="posts-nav" class="navigation"> <div class="nav-previous"><?php next_posts_link( '← ' . __( 'Older Posts', 'minimatica' ) ); ?></div> <div class="nav-next"><?php previous_posts_link( __( 'Newer Posts', 'minimatica' ) . ' →' ); ?></div> <div class="clear"></div> </div><!-- #nav-above --> <?php endif; ?> </div><!-- #content --> <?php else : ?> <div id="content"> <div id="post-0" <?php post_class(); ?>> <div class="entry-content"> <p><?php _e( 'The content you were looking for could not be found.', 'minimatica' ); ?></p> <?php get_search_form(); ?> </div><!-- .entry-content --> </div><!-- .post --> </div><!-- #content --> <?php endif; ?>
Thanks so much for helping Hakkim, I appreciate it!
Try this,
<?php /* * Template Name: Blog Page * Description: Custom Blog Page by muah, Kyle Chadha. */ get_header(); ?> <div class="title-container"> <h1 class="page-title"> <?php the_title(); ?> </h1> </div> <!-- .title-container --> <div id="container"> <?php global $post; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'posts_per_page' => 10, 'paged' =>$paged, 'post_type' => 'post', 'order' => 'DESC', 'orderby' => 'post_date' ); query_posts( $args ); ?> <?php if( have_posts() ) : ?> <div id="content" role="main"> <?php while( have_posts() ) : the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <header class="entry-header"> <?php if( has_post_thumbnail() ) : ?> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"> <?php the_post_thumbnail( 'homepage-thumb' ); ?> </a> <?php endif; ?> <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"> <?php the_title(); ?> </a></h2> <aside class="entry-meta<?php if( has_post_thumbnail() ) : ?> folded<?php endif; ?>"> <?php _e( 'By', 'minimatica' ); ?> <?php the_author_posts_link(); ?> <?php _e( 'on', 'minimatica' ); ?> <time datetime="<?php the_time( 'Y-m-d' ); ?>"> <?php the_time( get_option( 'date_format' ) ); ?> </time> </aside> <!-- .entry-meta --> </header> <!-- .entry-header --> <section class="entry-summary"> <?php the_excerpt(); ?> </section> <!-- .entry-summary --> <footer class="entry-footer"> <a class="more-link" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php echo __( 'Continue reading', 'minimatica' ) . ' →'; ?></a> </footer> <!-- entry-footer --> </article> <!-- .post --> <?php endwhile; ?> <?php if ( $wp_query->max_num_pages > 1 ) : ?> <div id="posts-nav" class="navigation"> <div class="nav-previous"> <?php next_posts_link( '← ' . __( 'Older Posts', 'minimatica' ) ); ?> </div> <div class="nav-next"> <?php previous_posts_link( __( 'Newer Posts', 'minimatica' ) . ' →' ); ?> </div> <div class="clear"></div> </div> <!-- #nav-above --> <?php endif; ?> </div> <!-- #content --> <?php else : ?> <div id="content"> <div id="post-0" <?php post_class(); ?>> <div class="entry-content"> <p> <?php _e( 'The content you were looking for could not be found.', 'minimatica' ); ?> </p> <?php get_search_form(); ?> </div> <!-- .entry-content --> </div> <!-- .post --> </div> <!-- #content --> <?php endif; ?> <?php get_sidebar(); ?> <div class="clear"></div> </div> <!-- #container --> <?php get_footer(); ?>
Hrm… still looks the same.
There’s also content.php and content-gallery.php — might they have something to do with it?
Content.php:
<?php /** * Displays the post content. Used as fallback for post formats * * @package WordPress * @subpackage Minimatica * @since Minimatica 1.0 */ ?> <div id="content"> <div class="entry-header"> <a class="colorbox" href="<?php $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' ); echo $thumbnail[0] ?>"> <?php the_post_thumbnail( 'single-thumb' ); ?> </a> <aside class="entry-meta"> <ul> <li><?php _e( 'Written by', 'minimatica' ); ?> <?php the_author_posts_link(); ?></li> <li><?php _e( 'on', 'minimatica' ); ?> <time datetime="<?php the_time( 'Y-m-d' ); ?>"><?php the_time( get_option( 'date_format' ) ); ?></time></li> <li><?php _e( 'Filed under', 'minimatica' ); ?> <?php the_category( ', ' ); ?></li> <?php edit_post_link( __( 'Edit', 'minimatica' ), '<li>', '</li>' ); ?> </ul> <?php the_tags( '<div class="entry-tags">', ' ', '</div>' ); ?> </aside><!-- .entry-meta --> <div class="clear"></div> </div><!-- .entry-header --> <section class="entry-content"> <?php the_content(); ?> <div class="clear"></div> <?php wp_link_pages( array( 'before' => '<p class="pagination">' . __( 'Pages' ) . ': ' ) ); ?> </section><!-- .entry-content --> <?php comments_template(); ?> </div><!-- #content -->
content-gallery.php
<?php /** * Displays the content of posts with gallery format * * @package WordPress * @subpackage Minimatica * @since Minimatica 1.0 */ ?> <div id="content"> <section class="entry-content"> <?php minimatica_post_gallery(); ?> <?php the_content(); ?> <div class="clear"></div> <?php wp_link_pages( array( 'before' => '<p class="pagination">' . __( 'Pages' ) . ': ' ) ); ?> </section><!-- .entry-content --> <div class="entry-header"> <aside class="entry-meta"> <ul> <li><?php _e( 'Posted by', 'minimatica' ); ?> <?php the_author_posts_link(); ?></li> <li><?php _e( 'on', 'minimatica' ); ?> <time datetime="<?php the_time( 'Y-m-d' ); ?>"><?php the_time( get_option( 'date_format' ) ); ?></time></li> <li><?php _e( 'Filed under', 'minimatica' ); ?> <?php the_category( ', ' ); ?></li> </ul> <?php the_tags( '<div class="entry-tags">', ' ', '</div>' ); ?> </aside><!-- .entry-meta --> <div class="clear"></div> </div><!-- .entry-header --> <?php comments_template(); ?> <div class="clear"></div> </div><!-- #content -->
Actually here’s the link to the theme directly: https://www.ads-software.com/themes/minimatica
Do this..
copy the content of your header.php file and create a new file called header-blog.php and paste it and save it.
then replace the current
<body>
tag in header-blog.php (it would be something like<body <?php body_class?>>
but whatever) with<body class="archive date" >
. Then call get_header(‘blog’); instead of get_header(); in your custom template.Actually was looking through the theme forums… and found a simple (albiet slightly less elegant) workaround.
Just adding all posts to a new category, ‘Blog’, and then having the blog link on the home page link to https://kylechadha.com/category/blog/
The only annoying part is all posts will show the category ‘Blog’!
Yes, that is why I did not recommend you to create a category. If you need to remove the ‘categoy’ from URL you have to modify the .htacess file or have to use some plugins. I think better to use the trick I mentioned in my last message. Try it. If that works there won’t come ‘category’ slug in the url.
- The topic ‘URL for all my blog posts?’ is closed to new replies.