WordPress custom post between every five posts - php

I'm trying to figure out how in the best way to accomplish what the image show.
I've been trying with modulus to do a if/else, but since the custom post is also a post there will be duplicates. I'm thinking about creating 2 custom queries, one with all the ordinary posts and one with the custom post, but that will make it slower and it doesn't seem like a good solution..
Here's the code of home.php in the wp-content\themes\theme\home.php
<?php
get_header(); ?>
<div id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<div id="posts" <?php hive_blog_class( 'archive__grid grid masonry' ); ?>>
<?php /* Start the Loop */
while ( have_posts() ) : the_post();
/* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
endwhile; ?>
</div>
<?php hive_paging_nav();
else :
get_template_part( 'content', 'none' );
endif; ?>
</div><!-- #main -->

Related

Wordpress loop not looping over posts

I am working on a Wordpress theme and for some reason even though I have posts it is showing that I do not have any posts.
<?php if(have_posts()){ ?>
<?php if ( is_home() && ! is_front_page() ) { ?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php while ( have_posts() ){ the_post(); ?>
<?php
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part('template-parts/content', get_post_format()); ?>
<?php } ?>
<?php the_posts_navigation(); ?>
<?php }else{ ?>
<?php get_template_part( 'template-parts/content', 'none' ); ?>
<?php } ?>
I'm having issues with debugging it since it shows their are posts.
I checked your code and it seems like you made a mistake in templates paths, they should be "template-parts/post/content" - you lost "post/" directory.

Make a Blog Template page on underscore.me with wordpress

i am trying to personalize a new theme made in underscore.me, but i can't seem to create a new template page with a loop that can show me posts of one specific category, how can i do this?
I'm gonna paste here the index.php of the underscore.me theme, witch has a generic loop, sadly, copying and pasting this loop on a template page does
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<?php if ( is_home() && ! is_front_page() ) : ?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php endif; ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'template-parts/content', get_post_format() );
?>
<?php endwhile; ?>
<?php the_posts_navigation(); ?>
<?php else : ?>
<?php get_template_part( 'template-parts/content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
And this is the page.php.
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/content', 'page' ); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
<?php endwhile; // End of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
Good news for you, you dont need a specific loop for a specific category.
if you have a category.php file in your theme, and assume that your category name is "Lux Cars" with id of "35". if you copy your category.php as category-35.php or category-lux-cars.php (slug of your category). When you open the posts with this category. wordpress call this file and show posts in that loop. you can edit your category-35.php and add any category detail or sth.
But if you still want a loop for a specific category then you can use that code;
<?php
$args = array ( 'category' => ID, 'posts_per_page' => 5);
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post);
?>
//Style Posts here
<?php endforeach; ?>

Removing automatic PHP page heading* (not title)

So I'm working on my blog page which uses a different page template, PHP isn't exactly my forte, and I feel like it should be a simple solution to remove the page header, but its all a bit out of my reach. This is my site, and my code looks like this:
<?php
/**
* Template Name: Blog
*/
get_header();
get_template_part( "closer" ); ?>
<div class="container">
<div class="row">
<div id="primary" <?php bavotasan_primary_attr(); ?>>
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile;
bavotasan_pagination();
else :
get_template_part( 'content', 'none' );
endif;
?>
</div>
<?php get_sidebar(); ?>
</div>
</div>
try to change this way,
Appearance > Editor > content-page.php (on the right side bar)>
Find: this statement
the_title();
and simply comment it out.
//the_title();
or do the above change in content.php file
I gave up, and used display: none in my CSS. Probably not the best way to go, but it works.

WordPress blog dates are displaying the current date for every post

My WordPress blog, which is running a custom theme, displays the date for each entry post as the same date: today. I display the last three posts on my main home page, but those dates are fine. However my main blog page shows the current date for every post.
I am able to FTP into my site, and have access to all the PHP files, the problem is I don't know which file this error might be in, whether it be index.php, page.php, single.php, I have no idea. If anyone can suggest where the problem might be, I can help by sharing that code.
Here is the index.php
<?php
get_header(); ?>
<div class="wrap blog">
<h1>Blog</h1>
<div class="blog-left">
<div id="main-content" class="main-content">
<?php
if ( is_front_page() && twentyfourteen_has_featured_posts() ) {
// Include the featured content template.
get_template_part( 'featured-content' );
}
?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php
if ( have_posts() ) :
// Start the Loop.
while ( have_posts() ) : the_post();
/*
* Include the post format-specific template for the content. If you want to
* use this in a child theme, then include a file called called content-___.php
* (where ___ is the post format) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
endwhile;
// Previous/next post navigation.
twentyfourteen_paging_nav();
else :
// If no content, include the "No posts found" template.
get_template_part( 'content', 'none' );
endif;
?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar( 'content' ); ?>
</div><!-- #main-content -->
</div>
<div class="blog-right">
<?php get_sidebar(); ?>
</div>
</div>
<?php
get_footer();
Have a look at template hierarchy chart to figure out which file is used to display those posts. It might be archive.php, front-page.php, home.php, index.php depending on the theme and setup. From there, you'll see the function or which file is loaded to display each post's content.
Considering the sample code, its probably in content.php or in case it's a special post format, in content-{format}.php
I'm almost sure that if the theme is using Template Tags, is using the_date function, when it should be using the_timefunction.
You can read the docs for the_date, in the description there's a note you should read.

including a template within another template in wordpress

I am developing a very simple wordpress project. One of the page will have thumbnails of my projects and some texts and when I will click on the thumbnails it will land me to the page corresponding to the project. I created a template where i am trying to include another template which will just hold the thumbnails. I want to be able to update the thumbnails and text from two different pages from the wordpress dashboard. This is what I have so far...the concept is kinda goofy...let me know if i explained it correctly
lets say this is the rendering template
<?php
/*
Template Name: projects
* This template displays project thumbnails and introductory copy as a rendering template
*/
$options = twentyeleven_get_theme_options();
$current_layout = $options['theme_layout'];
get_header();?>
<div id="primary">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<? /*php comments_template( '', true ); */?>
<?php endwhile; // end of the loop. ?>
<?php get_template_part( 'projectThumb', 'true' ); ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
and this is the thumbnail template.
<?php
/*
Template Name: projectThumb
* This template displays project thumbnails at the project page
*/
$options = twentyeleven_get_theme_options();
$current_layout = $options['theme_layout'];
get_header();?>
<div id="primary">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>

Categories