I don't know enough PHP perhaps to recognize immediately why the loop in my wordpress theme is only displaying one post and so I humbly ask for assisstance.
<div class="container">
<div class="row">
<div id="primary" class="content-area col-sm-8">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
<?php web2feel_content_nav( 'nav-below' ); ?>
<?php else : ?>
<?php get_template_part( 'no-results', 'index' ); ?>
<?php endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
</div>
</div>
<?php get_footer(); ?>
I believe that it then references the content.php file which is as follows
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php if ( 'post' == get_post_type() ) : ?>
<div class="entry-meta">
<?php web2feel_posted_on(); ?>
</div><!-- .entry-meta -->
<?php endif; ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->
<?php
$thumb = get_post_thumbnail_id();
$img_url = wp_get_attachment_url( $thumb,'full' ); //get full URL to image (use "large" or "medium" if the images too big)
$image = aq_resize( $img_url, 780, 400, true ); //resize & crop the image
?>
<?php if($image) : ?>
<img class="img-responsive" src="<?php echo $image ?>"/>
<?php endif; ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<footer class="entry-meta">
<?php if ( 'post' == get_post_type() ) : // Hide category and tag text for pages on Search ?>
<?php
/* translators: used between list items, there is a space after the comma */
$categories_list = get_the_category_list( __( ', ', 'web2feel' ) );
if ( $categories_list && web2feel_categorized_blog() ) :
?>
<span class="cat-links">
<?php printf( __( 'Posted in %1$s', 'web2feel' ), $categories_list ); ?>
</span>
<?php endif; // End if categories ?>
<?php
/* translators: used between list items, there is a space after the comma */
$tags_list = get_the_tag_list( '', __( ', ', 'web2feel' ) );
if ( $tags_list ) :
?>
<span class="tags-links">
<?php printf( __( 'Tagged %1$s', 'web2feel' ), $tags_list ); ?>
</span>
<?php endif; // End if $tags_list ?>
<?php endif; // End if 'post' == get_post_type() ?>
<?php if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) : ?>
<span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'web2feel' ), __( '1 Comment', 'web2feel' ), __( '% Comments', 'web2feel' ) ); ?></span>
<?php endif; ?>
<?php edit_post_link( __( 'Edit', 'web2feel' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-meta -->
</article><!-- #post-## -->
Any help would be appreciated. Thank you
I suggest you to check your settings from wordpress admin.
go to admin->Settings->Reading and check that Blog pages show at most should not be 1. if it's one than increase it.
Related
I've wrote this code to display a box with pageviews which is inside of the arrow button on the right side of every title, but the thing is, the counter is not counting pageviews on pages and I don't know why.
I added this code in index.php
I tried to put my code for pageviews inside of <?php is_singular( $post_types ); ?> like this:
<?php is_singular(
<div class="square">
<div class="pageviews-icon"></div>
<div class="pageviews"><?php echo getPostViews(get_the_ID()); ?></div>
</div>
); ?>
but is not working, the site crashed. Can anybody help me with this?
Here's the code above this as well, maybe it could help and I could wrap all together
<div class="frame">
<!-- uses the post format -->
<?php {
if(!get_post_format()) {
get_template_part('format', 'standard');
} else {
get_template_part('format', get_post_format());
};
?>
<div class="square">
<div class="pageviews-icon"></div><div class="pageviews"><?php echo getPostViews(get_the_ID()); ?></div>
</div>
</div>
The website: The link for the website
Here's the pageview code too:
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 Unique Views";
}
return $count.' Unique Views';
}
function setPostViews($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
}else{
$count++;
update_post_meta($postID, $count_key, $count);
}
}
You cannot put HTML in PHP. You can put STRINGS in PHP, but they need to be put in quotes.
if(is_single() || is_page() || is_attachment()) {
?>
<div class="square">
<div class="pageviews-icon"></div>
<div class="pageviews"><?php echo getPostViews(get_the_ID()); ?></div>
</div>
<?php
}
As the documentation says:
This conditional tag checks if a singular post is being displayed, which is the case when one of the following returns true: is_single(), is_page() or is_attachment(). If the $post_types parameter is specified, the function will additionally check if the query is for one of the post types specified.
You should do it like this:
<?php if is_singular() { ?>
<div class="square">
<div class="pageviews-icon"></div>
<div class="pageviews"><?php echo getPostViews(get_the_ID()); ?></div>
</div>
<?php }; ?>
Edit
You have to do some changes to your css:
div.frame{position:relative;}
div.square{display:block;}
Your view counter is functional. too see it live, please correct your php code as I mentioned above
live on your site :
You're going to want to do this in the file where you are looping through all your posts. This can be in different locations depending on your theme etc .
For the twentyfourteen theme this is in index.php and looks like this
PHP
<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() );
..... code carries on
The last line here: get_template_part tells us that it's pulling in a template called content if we go and open content.php we can see that this is where it actually outputs things specific for each page/post. This is where you will need to do your logic.
So for example, instead of this in twentyfourteen content.php
PHP:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php twentyfourteen_post_thumbnail(); ?>
<header class="entry-header">
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ) ) && twentyfourteen_categorized_blog() ) : ?>
<div class="entry-meta">
<span class="cat-links"><?php echo get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfourteen' ) ); ?></span>
</div>
<?php
endif;
if ( is_single() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
else :
the_title( '<h1 class="entry-title">', '</h1>' );
endif;
?>
<div class="entry-meta">
<?php
if ( 'post' == get_post_type() )
twentyfourteen_posted_on();
if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) :
?>
<span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyfourteen' ), __( '1 Comment', 'twentyfourteen' ), __( '% Comments', 'twentyfourteen' ) ); ?></span>
<?php
endif;
edit_post_link( __( 'Edit', 'twentyfourteen' ), '<span class="edit-link">', '</span>' );
?>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
You would do something like this
PHP:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php twentyfourteen_post_thumbnail(); ?>
<header class="entry-header">
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ) ) && twentyfourteen_categorized_blog() ) : ?>
<div class="entry-meta">
<span class="cat-links"><?php echo get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfourteen' ) ); ?></span>
</div>
<?php
endif;
if ( is_single() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
else :
the_title( '<h1 class="entry-title">', '</h1>' );
endif;
?>
<div class="square">
<div class="pageviews-icon"></div>
<div class="pageviews"><?php echo getPostViews(the_ID()); ?></div>
<div class="entry-meta">
<?php
if ( 'post' == get_post_type() )
twentyfourteen_posted_on();
if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) :
?>
<span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyfourteen' ), __( '1 Comment', 'twentyfourteen' ), __( '% Comments', 'twentyfourteen' ) ); ?></span>
<?php
endif;
edit_post_link( __( 'Edit', 'twentyfourteen' ), '<span class="edit-link">', '</span>' );
?>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
and then make sure that your getPostViews is accessible in your functions.php file.
This will make sure that your postViews are being displayed. But how to count them in the first place right?!
Go back to the content.php and have a look at this part of the code
PHP:
<?php if ( is_search() ) : ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<?php
the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyfourteen' ) );
wp_link_pages( array(
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentyfourteen' ) . '</span>',
'after' => '</div>',
'link_before' => '<span>',
'link_after' => '</span>',
) );
?>
</div><!-- .entry-content -->
<?php endif; ?>
The is_search() function says whether to display Excerpts for Search, home, category and tag pages. However we don't want to set a pageview each time the post shows up in the search or home etc, so we must only put the setPostViews call in the other part of that if i.e. when the post/page is being viewed on its own.
That'll give you code like this
PHP:
<?php if ( is_search() ) : ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<!-- Now we can add a pageview -->
<?php setPostViews(the_ID()); ?>
<div class="entry-content">
<?php
the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyfourteen' ) );
wp_link_pages( array(
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentyfourteen' ) . '</span>',
'after' => '</div>',
'link_before' => '<span>',
'link_after' => '</span>',
) );
?>
</div><!-- .entry-content -->
<?php endif; ?>
Again making sure that setPostViews is accessible in your functions.php file.
This should get you what you want.
I've figured it out were the code were messing up thanks to #RobSchmuecker, I was looking for bugs on the wrong place until he tells me about other pages so then I looked into all this code to see his statement, and I discovered where the code were messing up which was on a very bottom of a code page where I set it up the php views counter which the code was:
<?php if(is_single ()) { ?>
<?php setPostViews(get_the_ID()); ?>
<?php } ?>
instead of:
<?php if(is_singular ()) { ?>
<?php setPostViews(get_the_ID()); ?>
<?php } ?>
With many many hours of digging in code and trying stuff, I completly forgot about this part of the code. Thanks to all for helping me on this
Hi there I was wondering if anyone could assist me quickly.
I am working on a clients site and all of a sudden the blog posts only show the title and not the content.
I am not sure why and need some assistance.
here is the code for the single.php
<div id="primary" class="content-area">
<?php get_template_part( 'content', 'single' ); ?>
<div id="content" class="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php nightwatch_content_nav( 'nav-below' ); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template
if ( comments_open() || '0' != get_comments_number() )
comments_template( '', true );
?>
<?php endwhile; // end of the loop. ?>
</div><!-- #content .site-content -->
</div><!-- #primary .content-area -->
Thank you for your help.
*Edit
Here is the content-single.php code
<?php
/**
* #package nightwatch
* #since nightwatch 1.0.2
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-meta">
<?php nightwatch_posted_on(); ?>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( ' Pages:', 'nightwatch' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<footer class="entry-meta">
<?php
/* translators: used between list items, there is a space after the comma */
$category_list = get_the_category_list( __( ', ', 'nightwatch' ) );
/* translators: used between list items, there is a space after the comma */
$tag_list = get_the_tag_list( '', ', ' );
if ( ! nightwatch_categorized_blog() ) {
// This blog only has 1 category so we just need to worry about tags in the meta text
if ( '' != $tag_list ) {
$meta_text = __( 'This entry was tagged %2$s. Bookmark the permalink.', 'nightwatch' );
} else {
$meta_text = __( 'Bookmark the permalink.', 'nightwatch' );
}
} else {
// But this blog has loads of categories so we should probably display them here
if ( '' != $tag_list ) {
$meta_text = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the permalink.', 'nightwatch' );
} else {
$meta_text = __( 'This entry was posted in %1$s.
Bookmark the permalink.', 'nightwatch' );
}
} // end check for categories on this blog
printf(
$meta_text,
$category_list,
$tag_list,
get_permalink(),
the_title_attribute( 'echo=0' )
);
?>
<?php edit_post_link( __( 'Edit', 'nightwatch' ), '<span class="edit- link">', '</span>' ); ?>
</footer><!-- .entry-meta -->
</article><!-- #post-<?php the_ID(); ?> -->'
You should include the_content(); in the place you want the content to appear. Something like this:
<?php
while ( have_posts() ) : the_post();
the_content();
?>
Also, in the file content-single.php comment out (or delete) these lines:
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( ' Pages:', 'nightwatch' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
I have my theme page.php as:
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> >
<header class="entry-header">
<div class="hd"><?php the_title(); ?></div>
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<div class="video"><?php the_post_thumbnail(); ?></div>
<?php endif; ?>
<div class="hd"><?php //the_title(); ?></div>
</header><!-- .entry-header -->
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
<!-- .entry-content -->
<footer class="entry-meta">
<?php edit_post_link( __( 'Edit', 'twentythirteen' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-meta -->
</article><!-- #post -->
<?php // comments_template( '', true ); ?>
<?php endwhile; ?>
And I have made three page in wordpress blog, image and news and i also assigned them category for each. now i have installed php-exec plugin . Now I am writing some php code in page editor to retrieve blog data...
It working fine but it fetching data twice and now got it is becouse of page.php .
So can i have some condition on page.php if i am trying to fetch some data by cotegory then page.php data would not be display...
here is my code which i applied on blog page editor
<?php if (query_posts('cat=63&showposts=5')) : ?>
<?php while (have_posts()) : the_post();
// do whatever you want
?>
<div class="gallery_views">
<div class="hd"><?php the_title(); ?></div>
<?php // get_template_part( 'content', get_post_format() ); ?>
<?php // cup_post_nav(); ?>
<?php the_post_thumbnail(); ?>
<?php comments_template(); ?>
<b><?php the_title(); ?></b>
</div>
<?php endwhile; ?>
<?php else : ?>
Thanks in advance..
<?php if (query_posts('cat=63&showposts=5')) : ?>
<?php while (have_posts()) : the_post();
// do whatever you want
?><div class="gallery_views">
<div class="hd"><?php the_title(); ?></div>
<?php // get_template_part( 'content', get_post_format() ); ?>
<?php // cup_post_nav(); ?>
<?php the_post_thumbnail(); ?>
<?php comments_template(); ?>
<b><?php the_title(); ?></div>
<?php
break;
endwhile;
?>
<?php else : ?>
Add a break in your while, it'll stop after the first loop.
How can I edit the Php file for a Wordpress theme (shape - downloaded from themeshaper.com) to change the metadata.
for example current php file below displays the meta of a normal post like this:
for example instead of [avatar] [author] written on [date] like in the image above, I would like to change to Posted on [date] by [author].
Php File (content.php):
<?php
/**
* #package Shape
* #since Shape 1.0
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<!-- header content -->
<h1 class="entry-title"><?php the_title(); ?></h1><?php if ( 'post' == get_post_type() ) : ?>
<div class="entry-meta">
<?php shape_posted_on(); ?>
</div><!-- .entry-meta -->
<?php endif; ?><!-- end header content -->
</header><!-- .entry-header --><?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'shape' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'shape' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php endif; ?> <footer class="entry-meta">
<!-- footer content -->
<?php if ( 'post' == get_post_type() ) : // Hide category and tag text for pages on Search ?>
<?php
/* translators: used between list items, there is a space after the comma */
$categories_list = get_the_category_list( __( ', ', 'shape' ) );
if ( $categories_list && shape_categorized_blog() ) :
?>
<span class="cat-links">
<?php printf( __( 'Posted in %1$s', 'shape' ), $categories_list ); ?>
</span>
<?php endif; // End if categories ?> <?php endif; // End if 'post' == get_post_type() ?> <?php if ( 'post' == get_post_type() ) : // Hide category and tag text for pages on Search ?>
<?php
/* translators: used between list items, there is a space after the comma */
$tags_list = get_the_tag_list( '', __( ', ', 'shape' ) );
if ( $tags_list ) :
?>
<span class="sep"> | </span>
<span class="tag-links">
<?php printf( __( 'Tagged %1$s', 'shape' ), $tags_list ); ?>
</span>
<?php endif; // End if $tags_list ?>
<?php endif; // End if 'post' == get_post_type() ?><div style="float:right;"><?php if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) : ?>
<span class="sep"> | </span>
<span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'shape' ), __( '1 Comment', 'shape' ), __( '% Comments', 'shape' ) ); ?></span>
<?php endif; ?></div><!-- end footer content -->
<?php edit_post_link( __( 'Edit', 'shape' ), '<span class="sep"> | </span><span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-meta -->
</article><!-- #post-<?php the_ID(); ?> -->
contnet-aside php:
<?php
/**
* The template for displaying posts in the Aside post format
* #package Shape
* #since Shape 2.0
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'shape' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'shape' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<footer class="entry-meta">
<?php echo get_the_date(); ?>
<?php if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) : ?>
<span class="sep"> | </span>
<span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'shape' ), __( '1 Comment', 'shape' ), __( '% Comments', 'shape' ) ); ?></span>
<?php endif; ?>
<?php edit_post_link( __( 'Edit', 'shape' ), '<span class="sep"> | </span><span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-meta -->
</article><!-- #post-<?php the_ID(); ?> -->
I know it is late to answer but something like this will work if anyone else is interested
<p class="postmetadata">
<?php _e('Filed under:','domain'); ?>
<?php the_category(', ') ?> <?php _e('by','domain'); ?> <?php the_author(); ?>
<br/><?php the_tags(__('Tags:','domain'), ', ', '<br />'); ?>
<?php _e('Posted on: ','domain'); ?>
<?php the_time(get_option('date_format')); ?><br/>?>
<?php edit_post_link(__(' Edit','domain'), __(' |','domain'), ''); ?>
</p>
I am trying to style a category template that is based on the twenty twelve category.php template.
I believe i have amended the below to suit, however it is only displaying the header and no content, am i missing a line?
<?php get_header(); ?>
<?php if ( have_posts() ) : ?>
<header class="page-header">
<h1 class="page-title"><?php
printf( __( 'Category Archives: %s', 'D-Theme' ), '<span>' . single_cat_title( '', false ) . '</span>' );
?></h1>
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo apply_filters( 'category_archive_meta', '<div class="category-archive-meta">' . $category_description . '</div>' );
?>
</header>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'D-Theme' ); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'D-Theme' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->
<?php endif; ?>
</div><!-- #content -->
</section><!-- #primary -->
Help is appreciated as always
If you want to show the post content, you would need to use the_content() in your wordpress loop.
http://codex.wordpress.org/Function_Reference/the_content
I thought i would contribute my answer to the above. I have coded this to display my categories with a date, the person who posted it and a time it was posted, with a main title to display the title of the category in question.
Please see code and screenshot of what this produces, i hope this proves useful :)
<?php get_header(); ?>
<div id="maincontentwrap" role="main">
<h1 class="page-title"><?php
printf( __( 'Category Archives: %s', 'D-Theme' ), '<span>' . single_cat_title( '', false ) . '</span>' );
?></h1>
<div class="pagedivider"></div>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
Written by <?php the_author_posts_link() ?> in <?php the_category(); ?> at <?php the_time('H:h a'); ?>
<div class="pagedivider"></div>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>
<?php get_footer(); ?>