I have a blog.php with the following code:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1>
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?>
</a>
</h1>
<section>
<h3><?php the_category(); ?></h3>
<h5><?php the_date(); ?></h5>
<h5><?php posts_nav_link(); ?></h5>
</section>
<p class="articlemeta center"></p>
<?php if ( has_post_thumbnail() ) { the_post_thumbnail();} ?>
<?php the_content(); ?>
<?php edit_post_link( 'bearbeiten' ); ?>
<?php posts_nav_link(); ?>
<?php endwhile; else: ?>
<h2>
Sorry noch keine Texte vorhanden
</h2>
<section class="entry-utility">
<?php $tags_list = get_the_tag_list( '', ', ' ); if ( $tags_list ):?>
<span class="tag-links">
<?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?>
</span>
<span class="meta-sep">|</span>
<?php endif; ?>
</section>
<?php endif; ?>
My issue is now, that the dont compute a navigation. There is also no navigation when i paste the code at any other destination of the code. I hope anyone could help me to fix my issue.
Many thanks in advance.
I noticed you call <?php posts_nav_link(); ?> twice. I am not sure if this is an error because I don't have much to work with here.
I would take a look at the Wordpress Codex for guidance. An example they provide that might help is:
<div style="text-align:center;">
<?php posts_nav_link( ' · ', 'previous page', 'next page' ); ?>
</div>
Related
I'm attempting to build a category.php page for a custom Wordpress theme. Ideally, the page would find all category posts, then grab the sticky posts from that category, and if there's at least two, it would display them at the top (it's fine if these same posts repeat below).
This is the page I have built so far. It can gather all of the results without error, but the nested loop which tries to find the most recent two stickies fails. I receive the error:
"Warning: Attempt to assign property of non-object in C:\dev\xampp\htdocs\wordpress\wp-content\themes\ampersand\category.php on line 22"
How do I fix this loop? (I've included a github gist in case that's easier to read, category page for Wordpress theme in development)
<?php // Category Page Content Start ?>
<div id="content">
<main id="main" class="category-page" role="main" itemscope itemprop="mainContentOfPage" itemtype="http://schema.org/Periodical">
<h1><?php single_cat_title(); ?></h1>
<?php // Find all posts for the queried category ?>
<?php $catID = get_queried_object_id();
$args = array( 'numberposts' => -1, 'posts_per_page' => 20,
'cat' => $catID, 'post-type' => 'post' );
$query = new WP_query( $args ); $count = 0;
if ($query -> have_posts()) : ?>
<section class="featured">
<?php // Find the most recent sticky posts for this category; if at least 2, post them seperately ?>
<?php $sticky = get_option( 'sticky_posts' );
$findsticky = array( 'post__in' => $sticky, 'numberposts' => 2 );
$stickyposts = get_posts( $findsticky ); if ($stickyposts -> count = 2) :
foreach ($stickyposts as $post) : $post -> the_post(); ?>
<article class="featured-article" itemtype="http://schema.org/Article">
<meta itemprop="wordCount" content="<?php echo word_count(); ?>">
<figure class="thumbnail">
<div class="image-wrapper">
<a href="<?php the_permalink() ?>">
<img src="<?php the_post_thumbnail_url( 'thumb-small' ); ?>">
</a>
</div>
</figure>
<section>
<h2 class="headline">
<?php the_title(); ?>
</h2>
<span class="byline">
<?php $check = get_field( 'contributor' );
if ($check):?>
<span class="contributor" itemprop="author" itemtype="http://schema.org/Person">
<?php the_field( 'contributor' ); ?>
</span>
<?php else: ?>
<span class="contributor" itemprop="author" itemtype="http://schema.org/Person"><?php the_author_posts_link(); ?></span>
<?php endif; ?>
</span>
<?php $check = get_field( 'description' );
if ($check): ?>
<span class="description"><?php the_field( 'description' ); ?></span>
<?php else: ?>
<span class="excerpt"><?php the_excerpt(); ?></span>
<?php endif; ?>
</section>
</article>
<?php endforeach; endif; ?>
</section>
<section class="all-results">
<?php while ($query -> have_posts()) : $query -> the_post(); $count++; ?>
<article class="<?php echo 'article-'.$count; ?>" itemtype="http://schema.org/Article">
<meta itemprop="wordCount" content="<?php echo word_count(); ?>">
<figure class="thumbnail">
<div class="image-wrapper">
<a href="<?php the_permalink() ?>">
<img src="<?php the_post_thumbnail_url( 'thumb-small' ); ?>">
</a>
</div>
</figure>
<section>
<h2 class="headline">
<?php the_title(); ?>
</h2>
<span class="byline">
<?php $check = get_field( 'contributor' );
if ($check):?>
<span class="contributor" itemprop="author" itemtype="http://schema.org/Person">
<?php the_field( 'contributor' ); ?>
</span>
<?php else: ?>
<span class="contributor" itemprop="author" itemtype="http://schema.org/Person"><?php the_author_posts_link(); ?></span>
<?php endif; ?>
</span>
<?php $check = get_field( 'description' );
if ($check): ?>
<span class="description"><?php the_field( 'description' ); ?></span>
<?php else: ?>
<span class="excerpt"><?php the_excerpt(); ?></span>
<?php endif; ?>
</section>
</article>
<?php endwhile; ?>
</section>
<div class="pagination-bottom">
<?php if( get_next_posts_link() ) :
previous_posts_link( 'Older Posts' );
endif; ?>
<?php if( get_next_posts_link() ) :
next_posts_link( 'Newer Posts', 0 );
endif; ?>
</div>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; wp_reset_postdata(); ?>
</main>
</div>
I'm trying to use offset on a specific WP_Query on a page that has a total of 3 Loops with the code described here.
For now, this works but I can only target all three loops. What (I think) I have to do is change this part:
//Before anything else, make sure this is the right query...
if ( ! $query->is_posts_page ) {
return;
}
To something like this:
//Before anything else, make sure this is the right query...
if ( ! $query->$THELOOPIWANTTOTARGET ) {
return;
}
Is there a way to do this?
The query:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$mainloop = new WP_Query(array('posts_per_page' => 3, 'paged' => $paged));
?>
<div class="full padding center isotope">
<?php if ( $mainloop->have_posts() ) : while ( $mainloop->have_posts() ) : $mainloop->the_post(); ?>
<article class="post">
<?php the_post_thumbnail(); ?>
<div class="textwrap">
<h2><?php the_title(); ?></h2>
<?php if ( get_field('bron')): ?>
<?php if ( get_field('bron')): ?><a href="<?php the_field('bron_link'); ?>" target="_blank" class="source"><?php endif; ?>
<?php the_field('bron'); ?>
<?php if ( get_field('bron')): ?></a><?php endif; ?>
<?php endif; ?>
<?php the_excerpt(); ?>
</div>
<div class="readmore">
<div class="fa fa-share share" id="<?php the_ID(); ?>">
<div class="share_block"><div class="addthis_sharing_toolbox" data-url="<?php the_permalink(); ?>"></div></div>
</div>
Lees verder
</div>
</article>
<?php endwhile; ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</div>
Im having an issue with a theme i've been customizing. My blog post only shows ( 1 ) post and i cant seem to fix the issue in Admin > Reading > Blog pages show at most. The Value only stays at "1" even after save. The code i have here is in the Loop.php
<?php ?>
<article class="primary-content">
<?php $firstClass='first-post' ; ?>
<?php /* If there are no posts to display, such as an empty archive page */ ?>
<?php if ( ! have_posts() ) : ?>
<article role="main" class="the-content">
<h1><?php _e( '404 - I'm sorry but the page can't be found' ); ?></h1>
<p>Please try searching again or head back to the homepage.</p>
</article>
<?php endif; ?>
<?php ?>
<?php if (is_home()): ?>
<h1>
<?php if ( is_day() ) : ?><?php printf( __( '<span>Daily Archive</span> %s' ), get_the_date() ); ?>
<?php elseif ( is_month() ) : ?><?php printf( __( '<span>Monthly Archive</span> %s' ), get_the_date('F Y') ); ?>
<?php elseif ( is_year() ) : ?><?php printf( __( '<span>Yearly Archive</span> %s' ), get_the_date('Y') ); ?>
<?php elseif ( is_category() ) : ?><?php echo single_cat_title(); ?>
<?php elseif ( is_search() ) : ?><?php printf( __( 'Search Results for: %s' ), '<span>' . get_search_query() . '</span>' ); ?>
<?php elseif ( is_home() ) : ?>Blog<?php else : ?>
<?php endif; ?>
</h1>
<?php endif; ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php /* How to display standard posts and search results */ ?>
<article class="article-archive <?php echo $firstClass; ?>" id="post-<?php the_ID(); ?>">
<?php $firstClass="" ; ?>
<?php ?>
<?php if (is_front_page()) { ?>
<div class="home-summary">
<?php } else { ?>
<div class="entry-summary">
<?php } ?>
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( '%s' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<?php the_post_thumbnail( 'flozo-thumb');?>
</a>
<?php if (is_front_page()) { ?>
<h1><?php the_title(); ?></h1>
<?php } else { ?>
<h2><?php the_title(); ?></h2>
<?php } ?>
<?php the_excerpt(); ?>
<?php if ( is_home() ) : ?>
<p class="entry-meta">
<time datetime="<?php the_time('l, F jS, Y') ?>" pubdate>
<?php the_time( 'l jS F Y') ?>
</time>
</p>
<?php endif; ?>
</div>
</article>
<?php /*?>
<?php comments_template( '', true ); ?>
<?php */?>
<?php endwhile; // End the loop. Whew. ?>
<?php /* Display navigation to next/previous pages when applicable */ ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<div class="navigation">
<div class="nav-previous">
<?php next_posts_link( __( 'Older posts' ) ); ?>
</div>
<div class="nav-next">
<?php previous_posts_link( __( 'Newer posts' ) ); ?>
</div>
</div>
<!-- #nav-below -->
<?php endif; ?>
</article>
Any and all help with be greatly appreciated! Sorry if this was posted already.
L
I want to display recent images from wordpress gallery in the format like:
<div class="portfolio-item">
<div class="portfolio-overlay">
<img src="img/zoom.png" width="58" height="58" alt="" title="">
</div><!-- .portfolio-overlay-->
<img class="pi-img" src="HERE LINK ON IMAGE" alt="" title="">
</div><!-- .portfolio-item-->
How i should build my loop?
Thank You
If you sort the query results
"SELECT * FROM gallery ORDER BY date ASC LIMIT ?"
// where ? is the number of rows you want to return
you can just do a simple foreach loop:
foreach ($galleryPic as &$pic) {
//your code
}
First of all you should use thumbs for posts (read more about post's thumbs). Than in your category template use this loop:
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<article class="post">
<header>
<h2><?php the_title(); ?></h2>
<span class="date"><time datetime="<?php the_time('Y-m-d'); ?>"><?php the_time('j F Y'); ?> <?php _e('в');?> <?php the_time('G:i'); ?></time></span>
<span class="author"><?php _e( 'Author:', 'nikita-sp' ); ?> <?php the_author(); ?></span>
<span class="category"><?php _e( 'in category', 'nikita-sp' ); ?> <?php the_category(', '); ?></span>
<span class="comments"><?php comments_popup_link( __( '0 comments', 'nikita-sp' ), __( '1 comment', 'nikita-sp' ), __( '% comments', 'nikita-sp' )); ?></span>
<?php edit_post_link( "Edit", '<span class="edit">', '</span>'); ?>
</header>
<?php the_content('read more...'); ?>
</article>
<?php endwhile; ?>
<?php wp_pagenavi(); ?>
<?php else : ?>
<article>
<h2><?php printf( __( 'SEARCH RESULT for: %s' ), '<span>' . esc_html( get_search_query() ) . '</span>' ); ?></h2>
<p class="center"><?php _e( 'Sorry, nothing was found', 'nikita_sp' ); ?></p>
<?php get_search_form(); ?>
</article>
<?php endif; ?>
Also use thumb output where y want.
<?php if ( has_post_thumbnail()) : ?>
<?php the_post_thumbnail(); ?>
<?php endif; ?>
I wish to insert a line of code inside my wordpress main page index.php which would display all posts except for posts that fall in 'Diary' category.
the original line of code is as follows
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<div <?php post_class(); ?>>
<span class="postlabel"><span><?php the_time('d'); ?></span><?php the_time('M'); ?></span>
<h2 class="post-title"><?php the_title(); ?></h2>
<p class="info">
<span class="catinfo"><?php _e('Filed in ', 'Mflat');?><?php the_category(' | ') ?></span>
<span class="cmtinfo"><?php comments_popup_link( __( 'Leave a comment', 'Mflat' ), __( '1 Comment', 'Mflat' ), __( '% Comments', 'Mflat' ) ); ?><?php edit_post_link(' Edit', ' | ', ''); ?></span>
</p>
<div class="entry">
<?php $Mflat_options = get_option('Mflat_theme_options'); ?>
<?php if ( $Mflat_options['home_excerpt_check']== 1 ) { the_excerpt(__('» Read more','Mflat')); } else {the_content(__('Continue Reading','Mflat'));} ?>
</div>
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
<p class="infobottom">
<?php if(function_exists('the_views')): ?><span class="count"><?php the_views(); ?></span><?php endif; ?>
<?php if (has_tag()): ?><span class="tags"><?php the_tags(' '); ?></span><?php endif; ?>
</p>
</div>
<?php endwhile; ?>
<div class="flip">
<div class="prevpost"><?php next_posts_link(__('Older Entries', 'Mflat')) ?></div>
<div class="nextpost"><?php previous_posts_link(__('Newer Entries', 'Mflat')) ?></div>
</div>
<?php else : ?>
<div id="main">
<h2><?php _e('Not Found', 'Mflat'); ?></h2>
</div>
<?php endif; ?>
I tried the following codes but to no avail
<?php if(have_posts()) : ?><?php while(have_posts()){
<if(!in_category('Diary')){
: the_post();
}
}?>
Is there any better way i can get this done?
I am new to PHP and though i know the logic of what has to be done, i cant quite generate the code to make this work. I think boolean would be a little too much work and found a similar (http://stackoverflow.com/questions/13587958/display-recent-posts-based-on-their-category-in-wordpress) thread on stark overflow but it doesnt quite suit my needs.
Every contribution is dearly appreciated. Thanks
just run the query_posts() function before the loop - it alters the loop
<?php
query_posts(array(
'category_name' => 'my-category-slug', // get posts by category name
'posts_per_page' => -1 // all posts
));
?>
<?php while(have_posts()): the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; ?>
My bad, I just noticed you want to exclude a category. Same function, different arguments:
$category = get_term_by('name', $cat_name, 'category'); // get category
$id = $category->term_id; // get the category ID
query_posts('cat=-' . $id); // exclude the found ID
<?php
$category = get_term_by('name', 'Diary', 'category'); // get category data
$id = $category->term_id; // get the category ID
// USE THIS IF YOU WANT TO _EXCLUDE_ ALL POSTS FROM "DIARY"
query_posts($query_string . '&cat=-' . $id);
// USE THIS IF YOU WANT TO GET ALL POSTS FROM "DIARY" ONLY
// query_posts($query_string . '&cat=' . $id);
?>
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<div <?php post_class(); ?>>
<span class="postlabel"><span><?php the_time('d'); ?></span><?php the_time('M'); ?></span>
<h2 class="post-title"><?php the_title(); ?></h2>
<p class="info">
<span class="catinfo"><?php _e('Filed in ', 'Mflat');?><?php the_category(' | ') ?></span>
<span class="cmtinfo">
<?php comments_popup_link( __( 'Leave a comment', 'Mflat' ), __( '1 Comment', 'Mflat' ), __( '% Comments', 'Mflat' ) ); ?>
<?php edit_post_link(' Edit', ' | ', ''); ?>
</span>
</p>
<div class="entry">
<?php $Mflat_options = get_option('Mflat_theme_options'); ?>
<?php if ( $Mflat_options['home_excerpt_check']== 1 ) { the_excerpt(__('» Read more','Mflat')); } else {the_content(__('Continue Reading','Mflat'));} ?>
</div>
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
<p class="infobottom">
<?php if(function_exists('the_views')): ?><span class="count"><?php the_views(); ?></span><?php endif; ?>
<?php if (has_tag()): ?><span class="tags"><?php the_tags(' '); ?></span><?php endif; ?>
</p>
</div>
<?php endwhile; ?>
<div class="flip">
<div class="prevpost"><?php next_posts_link(__('Older Entries', 'Mflat')) ?></div>
<div class="nextpost"><?php previous_posts_link(__('Newer Entries', 'Mflat')) ?></div>
</div>
<?php else : ?>
<div id="main">
<h2><?php _e('Not Found', 'Mflat'); ?></h2>
</div>
<?php endif; ?>