I have a set-up a custom theme on my wordpress install. I have been developing with it locally and everything was working fine.
I uploaded to my server tonight and was setting up the fresh wordpress install. I turned on permalinks and all of a sudden my custom category pages are causing infinite re-direct loops.
My .htaccess is writable so I don't think its that problem (I have seen this mentioned a lot online).
The code from one of my custom pages is below - it pulls from a specific category - does anyone know how to fix this issue?
<?php get_header(); ?>
<?php
/*
Template Name: Podcasts
*/
?>
<ul class="mcol">
<?php
query_posts("cat=1");
while(have_posts()) : the_post(); ?>
<li class="article" id="post-<?php the_ID(); ?>">
<?php
if ( has_post_thumbnail() ) { ?>
<?php
$imgsrcparam = array(
'alt' => trim(strip_tags( $post- >post_excerpt )),
'title' => trim(strip_tags( $post->post_title )),
);
$thumbID = get_the_post_thumbnail( $post->ID, array(200,200), $imgsrcparam ); ?>
<div class="preview"><?php echo "$thumbID"; ?><div class="front-titles"><?php the_title(); ?></div></div>
<?php } else {?>
<div class="preview"><img src="<?php bloginfo('template_url'); ?>/images/default-thumbnail.jpg" alt="<?php the_title(); ?>" /></div>
<?php } ?>
<div class="article-over">
</div>
</li> <?php ?>
<?php endwhile;
//Reset Query
wp_reset_query();
?>
</ul>
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<?php endwhile; ?>
<?php else : ?>
<h1 id="error"><?php _e("Sorry, but you are looking for something that isn’t here."); ?></h1>
<?php endif; ?>
<div class="pagination"><?php previous_posts_link('<< Newer Entries', 0) ?> <?php next_posts_link('Older Entries >>', 0); ?> </div>
<?php get_footer(); ?>
Anyone any ideas? I'm quite new to this so am unsure as to what the problem might be...
What your doing is weird.
query_posts is meant to alter the main loop.
You have 2 loops with different syntax on the same page.
The second loop is not doing anything, so remove it, and use get_posts or WP Query for your custom query.
Related
I have an if/else to call the template for a post type, and for some reason I cannot seem to figure out why the first portion is stuck in an infinite loop.
Here's the main page loop:
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<?php if ( has_term('bands', 'work_family')):
get_template_part('content', 'single-bands');
else:
get_template_part('content', 'single-work');
endif; ?>
<?php endwhile; endif; ?>
I'm pretty sure the problem is in the single-bands template that is getting loaded, because if I comment out that line and stick some text in there it works just as it should. Here's that template:
<header class="fl-post-header">
<h1 class="fl-post-title" itemprop="headline">
<?php
// strip "Songs by" from titles for archive page
$title = get_the_title();
$prefix = 'Songs by ';
$stripper = $title;
if (substr($stripper, 0, strlen($prefix)) == $prefix) {
$stripper = substr($stripper, strlen($prefix));
}
?>
<?php echo $stripper; ?>
<?php edit_post_link( _x( 'Edit', 'Edit post link text.', 'fl-automator' ) ); ?>
TEMPLATE LOADED CORRECTLY IF YOU SEE THIS
</h1>
</header><!-- .fl-post-header -->
<div class="fl-content <?php FLTheme::content_class(); ?>">
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<article <?php post_class( 'work-post' ); ?> id="fl-post-<?php the_ID(); ?>" itemscope="itemscope">
<?php the_content(); ?>
<?php get_template_part('content', 'band-performances') ?>
<?php endwhile; endif; ?>
</div>
Nothing else loop related on the page and all the html works fine when I load the template directly instead of in that outer loop from the other page. I'm relatively certain the problem is in the header, because the rest of the template does not get looped, just that.
I am building a custom theme from scratch and come across a slight problem that I need some help with.
So I have on my front-page a list of the 3 latest blog posts showing the 'title', 'Excerpt' & a 'more...' link which both the title and more link take you to single.php.
I am generating the post content in a file named 'content-post.php' which is the following:
<div class="clearfix">
<?php echo get_the_post_thumbnail( $post_id, $size, $attr ); ?>
<header class="title">
<h3><?php the_title(); ?></h3>
</header>
<ul class="info">
<li><?php the_category(', '); ?> | <?php the_time('F Y'); ?></li>
<!--<li>Written By: <a href="<?php bloginfo('siteurl') ?>/about/"><?php the_author(); ?></li>-->
</ul>
<div class="excerpt">
<p><?php if(is_single()): ?>
<?php the_content(); ?>
<?php comments_template(); ?>
<?php else: ?>
<?php the_excerpt(); ?>
<a class="post-link" href="<?php the_permalink(); ?>">More...</a></p>
<?php endif; ?>
</div>
</div>
This builds the posts out to front-page.php just fine. I am having the problem when you go into the blog page which is using the same post content and the layout is the same. Is there a way I can specify how it shows on the front-page and how it appears on the blog page?
The post is being displayed on front-page.php like this:
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( 'content', 'post' ); ?>
<?php endwhile; endif; ?>
And on the blog page like this:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'post' ); ?>
<?php endwhile; else: ?>
<p>There are no posts to display or pages here</p>
<?php endif; ?>
If I understand your question, try this:
<?php if (is_page(page id)){your query}
Good luck! ;)
PS.. or on your way:
<?php if (is_page(page id)): ?>
your query
<?php endif; ?>
I am developing my first WordPress site and started the process by developing on a local server via MAMP, using the theme "nine". All worked well and I was able to enable comments on all pages.
After I tried to migrate from MAMP to live server, without succeeding, i decided to create the website on the live server from scratch, which is not a big job as the website is not that big.
However I am not able to enable comments on all pages, BTW this is not a blog, and i am stuck.
I have been reading all kinds of things on internet but not succeeded and really need help.
Here is a few screenshots on some of the details that i think is important, they are in Swedish i am afraid.
Below is the page.php file:
<?php global $data;
get_header(); ?>
<div class="page-wrap">
<?php get_template_part( 'framework/inc/slider' ); ?>
<div id="page-body" class="page-body">
<div class="container"><?php
get_template_part( 'framework/inc/titlebar' ); ?>
<div class="row">
<div class="span12"><?php
if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>><?php
the_content();
wp_link_pages(array('before' => 'Pages: ', 'next_or_number' => 'number')); ?>
</article><?php
if(!$data['check_disablecomments']) {
comments_template();
}
endwhile; endif; ?>
</div>
</div>
</div>
My understanding is that i may have to add "" somewhere in this code.
Here is a few screenshots (Swedish) of, what i think, important pages:
++++
++++
Thanks to Anju Raghunath I was able to solve this problem by updating the page.php and add:
<?php comments_template(); ?>
after the:
"endwhile; endif; ?>" line.
See below in the updated page.php:
<?php global $data;
get_header(); ?>
<div class="page-wrap">
<?php get_template_part( 'framework/inc/slider' ); ?>
<div id="page-body" class="page-body">
<div class="container"><?php
get_template_part( 'framework/inc/titlebar' ); ?>
<div class="row">
<div class="span12"><?php
if (have_posts()) : while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>><?php
the_content();
wp_link_pages(array('before' => 'Pages: ', 'next_or_number' => 'number')); ?>
</article><?php
if(!$data['check_disablecomments']) {
comments_template();
}
endwhile; endif; ?>
<?php comments_template(); ?>
</div>
</div>
</div>
I'm currently trying to develop a custom Wordpress theme, and on my homepage I need to add a second content block. I am using a plugin to do this, which simply requires me to add the following where I want the content block to be.
<?php the_block('Latest Products')?>
However when I add this it seems to have no effect which I believe is due to the formatting of my php. I'm fairly new to php, so any help is greatly appreciated.
My code is as follows - I've cut out the best part of the HTML. I think it's something to do with that 'endforeach' tag?
<?php get_header(); ?>
<?php if(have_posts()) :?>
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php
global $post;
$myposts = get_posts('numberposts=4&category=1');
foreach($myposts as $post) :
?>
<div class="blogsnippet">
<div class="postdate">
<span class="top"><?php the_time ('j')?></span><br/><span class="bottom"><?php the_time('M');?></span>
</div>
<div class="postexcerpt">
<h3><?php the_title(); ?></h3>
<p><?php echo(get_the_excerpt());?></p>
</div>
</div>
<?php endforeach;?>
<?php the_block('Latest Products')?>
<?php endwhile; endif; ?>
<?php get_footer(); ?>
EDIT
Okay, so apparently it needs to be put outside the loop, however it still won't work. Any ideas?
<?php get_header(); ?>
<?php if(have_posts()) :?>
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php
global $post;
$myposts = get_posts('numberposts=4&category=1');
foreach($myposts as $post) :
?>
<div class="blogsnippet">
<div class="postdate">
<span class="top"><?php the_time ('j')?></span><br/><span class="bottom"><?php the_time('M');?></span>
</div>
<div class="postexcerpt">
<h3><?php the_title(); ?></h3>
<p><?php echo(get_the_excerpt());?></p>
</div>
</div>
<?php endforeach;?>
<?php endwhile; endif; ?>
<?php the_block('Latest Products')?>
<?php get_footer(); ?>
This mostly depends on what the plugin is actually doing because your code syntax is correct.
If you are using the Multiple Content Blocks plugin and are using the latest Wordpress version 3.5.1 then I believe the plugin may not be compatible. I'd check the version compatibility of the plugin to your Wordpress install as this could be your issue.
EDIT:
The plugin works by applying a filter to the function the_content() so that is why it only works by declaring the_block() before the_content() function is called.
A solution could be to capture the output the_block() and use print it out later, as an example:
<?php
ob_start();
the_block('Latest Products');
$latest_products_contents = ob_get_contents();
ob_end_clean();
?>
<!-- Further down.. -->
<?php echo $latest_products_contents; ?>
Its been a while since ive done wordpress templating and for some reason i cant get the archives.php to work. i have this:
<?php
/* Template Name: Archives */
get_header(); ?>
<div id='content'>
<?php get_sidebar('left'); ?>
<div id='column2-wide'>
<?php if (have_posts()): while (have_posts()): the_post(); ?>
<?php if ( in_category(16) ) { ?>
<h2><?php the_title(); ?></h2>
<div class="post">
<?php echo the_content(); ?>
</div>
<?php } ?>
<?php endwhile; endif; ?>
</div><!-- column2 -->
<?php get_footer(); ?>
Then created a page in the admin and chosen the Archives template to be used from the dropdown.
However the posts just dont seem to show. Am i missing something? The very same code works in the index.php file. It seems its just not working when im trying to display posts in a page.
It could well be im missing a file as I started developing the theme using a skeleton theme by Kennethreitz which can be found here:
https://github.com/kennethreitz/wordpress-theme-skeleton/
Any help would be appreciated.
Thanks for reading.
fl3x7
EDIT--> Also ive removed the category check so it should just list all posts but instead what it does is just echo the title of the current page if that helps
I'm assuming that "16" is the category ID? According to the WordPress docs for in_category, if you're querying by ID it should be passed as an integer.
$category
(mixed) (required) One or more categories specified by ID
(integer), name or slug (string), or an array of these
With your current code, the in_category check is failing every time since it is checking for an association with the category named "16." Try this instead:
if ( in_category(16) ) {
...
}
Thanks to the help provided by Hans. This is what I did:
query_posts( array ( 'category_name' => 'foo', 'posts_per_page' => 10 ) );
if (have_posts()): while (have_posts()): the_post(); ?>
<h2><a href='<?php the_permalink(); ?>'><?php the_title(); ?></a></h2>
<div class="post">
<?php echo the_excerpt(); ?>
</div>
<?php endwhile; endif; ?>