Custom Blog Post Listing in Genesis Sample Child Theme - wordpress

I want to add several images and divs and also customize the look of my Blog post listing... But i can't find the way to do it.
Here's the Blog Template code
<?php
/*
WARNING: This file is part of the core Genesis framework. DO NOT edit
this file under any circumstances. Please do all modifications
in the form of a child theme.
*/
/**
* Template Name: Blog
* This file handles blog post listings within a page.
*
* This file is a core Genesis file and should not be edited.
*
* The blog page loop logic is located in lib/structure/loops.php
*
* #category Genesis
* #package Templates
* #author StudioPress
* #license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
* #link http://www.studiopress.com/themes/genesis
*/
genesis();
and just above the genesis(); code.. i tried to put some divs and images there.. But i guess that's not the way it works. ..
I also tried to make my own Blog listing template using a normal wordpress code theme..
<?php /*
Template Name: List Post Pages
*/
?>
<?php get_header(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div class="featured">
<?php the_post_thumbnail(); ?>
</div>
<?php } ?>
<div class="divider"></div>
<div id="content" class="hfeed">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>">
<?php the_title(); ?>
</a></h2>
<div class="entry">
<?php the_content(); ?>
</div>
<div class="postmetadata">
<?php the_tags('Tags: ', ', ', '<br />'); ?>
Posted in
<?php the_category(', ') ?>
|
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
<?php genesis_after_loop(); ?>
</div>
<?php get_footer(); ?>
But no luck, what's the right way to do this?
***Update -code below is the one i want.. but instead of having the Content of the page. I want the list of Post with excerpts ....How can i do that????
<?php /*
Template Name: Page Template
*/ ?>
<?php get_header(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div class="featured">
<?php the_post_thumbnail(); ?>
</div>
<?php } ?>
<div class="divider"></div>
<?php genesis_before_content_sidebar_wrap(); ?>
<div id="content-sidebar-wrap">
<?php genesis_before_content(); ?>
<div id="content" class="hfeed">
<?php genesis_before_loop(); ?>
<?php genesis_loop(); ?>
<?php genesis_after_loop(); ?>
</div>
<!-- end #content -->
<?php genesis_after_content(); ?>
</div>
<!-- end #content-sidebar-wrap -->
<?php genesis_after_content_sidebar_wrap(); ?>
<?php get_footer(); ?>

Im shocked that no one answered my question.. anyway, if someone bumps onto this post with similar problem. The answer is adding
<?php query_posts( $args ); ?>
just above the <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
All in all, my code looks like this ...
<?php /*
Template Name: Page Template
*/ ?>
<?php get_header(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<div class="featured">
<?php the_post_thumbnail(); ?>
</div>
<?php } ?>
<div class="divider"></div>
<?php genesis_before_content_sidebar_wrap(); ?>
<div id="content-sidebar-wrap">
<?php genesis_before_content(); ?>
<div id="content" class="hfeed">
<?php genesis_before_loop(); ?>
<?php query_posts( $args ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>">
<?php the_title(); ?>
</a></h2>
<div class="entry">
<?php the_content(); ?>
</div>
<div class="postmetadata">
<?php the_tags('Tags: ', ', ', '<br />'); ?>
Posted in
<?php the_category(', ') ?>
|
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
</div>
</div>
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
<?php genesis_after_loop(); ?>
</div>
<!-- end #content -->
<?php genesis_after_content(); ?>
</div>
<!-- end #content-sidebar-wrap -->
<?php genesis_after_content_sidebar_wrap(); ?>
<?php get_footer(); ?>

Related

Removing date from pages not posts in search results (Wordpress)

I'm trying to remove the date from pages only in search results.
I found this: https://wordpress.org/support/topic/search-results-hide-date-for-pages-not-posts - however, I can't seem to figure out where to add it without causing errors.
I also found an answer suggesting just removing the date code from page.php but I don't have that in there anyway.
My search.php:
<?php get_header(); ?>
<?php get_sidebar(); ?>
<div id="content">
<div class="article">
<?php
$wp_query->query_vars["posts_per_page"] = 16;
$wp_query->get_posts();
?>
<?php if ( have_posts() ) : ?>
<?php
global $wp_query;
$total_results = $wp_query->found_posts;
?>
<?php printf( __( 'Search results for: %s', 'shape' ), '<span>' . get_search_query() . '</span>' ); ?>
<br/><br/>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="searchresultsdate">
<?php the_time('M j, Y') ?> </div><div class="searchresults"><?php the_title(); ?></div>
<?php endwhile; ?>
</div>
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
else { ?>
<div class="right"><?php next_posts_link('Next Page »') ?></div>
<div class="left"><?php previous_posts_link('« Previous Page') ?></div>
<?php } ?>
<br><br><br>
<?php else : ?>
<div class="posttitle">Nothing found. Try something else?</div>
This page doesn't exist
<?php endif; ?>
<?php get_footer(); ?>
Change
<div class="searchresultsdate">
<?php the_time('M j, Y') ?>
</div>
to
<?php if ("page" != get_post_type()){ ?>
<div class="searchresultsdate">
<?php the_time('M j, Y'); ?>
</div>
<?php } ?>
Also you're missing ';' in many places.

Wordpress query_posts() not returning list of posts whilst excluding one category

I'm having some trouble witin one of my page templates for my Wordpress theme. I wish to list all post but exclude those from one category (id: 4).
Below I have used query_posts() as per the Codex documentation:
<?php get_header(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<header
<?php
if ( has_post_thumbnail()) {
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large');
echo 'style="background-image:url(' . $large_image_url[0] . ')"';
}
?>
>
<div class="row">
<div class="page-title small-12 large-8 columns">
<h1>
<?php the_title(); ?>
</h1>
</div>
</div>
</header>
<?php get_template_part( 'content', 'headerbanner' ); ?>
<?php endwhile;?>
<section class="container main-content">
<div class="row">
<div id="content" class="small-12 columns">
<?php query_posts($query_string . '&cat=-4'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
</div>
</div>
</section>
<?php get_footer(); ?>
The problem is that this does not return a list of the posts. Instead it only returns the details for the page itself (in this case called "blog").
Amending the code from inside #content to the following solved this problem:
<?php query_posts('cat=-4'); ?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
here you need to pass post_type
query_posts($query_string . '&cat=-4&post_type=post');

Can't show / hide a part in WordPress with the normal loop

I tried the following. When there is content to show, show it + show H3 <h3>Overview</h3>, if not show noting.
But this will not work for me.
My code:
<?php
$heroimage = get_field('hero_image' );
$alt = $image['title' ];
?>
<?php if ($heroimage) : ?>
<div class="grid_12">
<img src="<?php echo $heroimage; ?>" alt="<?php echo $alt; ?>"/>
</div><!-- End div.grid_12 -->
<?php endif; ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="grid_8">
<h3>Overview</h3>
<?php the_content(); ?>
</article><!-- End article.grid_8 -->
<?php endwhile; ?>
The first part of the Hero image is to get the image from the plugin Advanced Custom Fields. The problem lies on the if have_posts etc..
Thanks for advance!
regarding to the codex, it should be
<?php
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<article class="grid_8">
<h3>Overview</h3>
<?php the_content(); ?>
</article><!-- End article.grid_8 -->
<?php endwhile;
endif;
?>
You forgot to close your if statement.

WordPress Query Posts To Show All & Style Each One

I am trying to include every post onto my index page on WordPress and have each one of them be styled with the included CSS. I am able to query all of the posts and have them show up, but only the first post is actually styled. The rest inherit the base h1, h2, p and other generic styles, but they aren't inheriting the "box" class for each one. All of the information is being thrown into one 'box' class instead of starting a new 'box' class for each post like I would like it to do. Any help on this would be appreciated.
Here is my code I am using
<?php get_header(); ?>
<div id="index-float-left">
<div class="box">
<?php query_posts( 'showposts=-1' ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
<p class="post-date"><?php echo $post_date = get_the_date(); ?></p>
</div>
</div> <!-- END BOX -->
</div> <!-- FLOAT BOX BOX -->
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
There is a problem with "End Box" and "Fload Box Box". Can you try like this:
<?php get_header(); ?>
<div id="index-float-left">
<?php query_posts( 'showposts=-1' ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="box">
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
<p class="post-date"><?php echo $post_date = get_the_date(); ?></p>
</div>
</div> <!-- END BOX -->
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
</div> <!-- FLOAT BOX BOX -->
<?php get_sidebar(); ?>

WordPress Pagination on Page

I have the following code on a WordPress page. It basically just grabs 3 posts and displays them as well as the page content itself up top. What I want to add is pagination so that a user can flick through all the posts, how do I get this working with custom loops like this?
<?PHP
get_header();
/* Template Name: News */
?>
<div style="padding: 0 20px;">
<div class="box clearfix side" style="margin:10px 0;">
<div style="float:left;width:628px;">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="content" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?><?php edit_post_link('Edit', ' <small>[', ']</small>'); ?></h2>
<?php the_content('<p>Read the rest of this page »</p>'); ?>
<?php wp_link_pages(array('before' => '<p>Pages: ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
<hr />
</div>
<?php endwhile; endif; ?>
<hr />
<?php $blog_query = new WP_Query('posts_per_page=3'); while ($blog_query->have_posts()) : $blog_query->the_post(); ?>
<div class="content" id="post-<?php the_ID(); ?>">
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
<?php if ($blog_query->have_posts()) : ?>
<?php if(function_exists('wp_pagenavi'))
{
wp_pagenavi();
}
?>
<?php else: ?>
<h2>oooops!!!</h2>
<?php endif; ?>
</div>
</div>
</div>
<?PHP
get_footer();
?>
Are you sure you're not re-inventing the wheel a little here? Why not set the number of posts to display in the admin, then use WP's native paging for the blog?
Turns out you have to do something like this:
<?php $temp = $wp_query; $wp_query= null; ?>
<?php $wp_query = new WP_Query(array('posts_per_page' => 3, 'paged' => $paged)); while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="content" id="post-<?php the_ID(); ?>">
<h4><?php the_title(); ?></h4>
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
<?php if(function_exists('wp_pagenavi'))
{
wp_pagenavi();
}
?>
<?php $wp_query = null; $wp_query = $temp; ?>

Resources