WP – Content code keeps subpage from appearing in sidebar - wordpress

In one of my wordpress templates, the content code seems to keep the subpage menu from displaying in the sidebar. When ever I remove all code from the content div, the subpage menu appears as expected.
Could anyone point out where the code goes wrong?
Any help would be greatly appreciated!
<div id="content">
<div class="pageinfo clearfix">
<div class="info">
<h1><?php the_title();?></h1>
</div>
</div>
<?php
global $more;
// set $more to 0 in order to only get the first part of the post
$more = 0;
global $post;
$myposts = query_posts("category_name=intern&posts_per_page=3");
foreach($myposts as $post) :
setup_postdata($post);
?>
<div class="postitem clearfix">
<div class="new"></div>
<div class="info">
<h2><?php the_title()?></h2>
<?php the_date()?> | Skrevet af <?php the_author_posts_link(); ?> | Gemt under:
<?php
// heres just the name and permalink:
foreach((get_the_category()) as $category) {
$category_name = $category->category_nicename . ' ';
$category_link = get_category_link($category->cat_ID);
echo "<a href='$category_link'>$category_name</a>";
}
?>
</div>
<?php
$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];?>
<?php if($thumb != NULL) { ?>
<a href="<?php the_permalink() ?>">
<img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo $thumb ?>&h=110&w=110&zc=1" alt="<?php the_title(); ?>" width="110" height="110" class="leftImage" >
</a>
<?php } ?>
<?php the_content('<br />Læs resten her » '); ?>
<div class="clearBoth"></div>
</div><!-- /postitem -->
<?php endforeach; ?>
</div><!-- /content -->

try rewind_posts(); or wp_reset_query(); somewhere before your sidebar is loaded up (and after the endforeach).

Related

Using a custom ACF image size in a while loop

I am trying to display an image in a while loop that uses a custom image size set-up in the functions.php file.
The code below is:
<?php
elseif(get_row_layout() == 'services_list'):
$image = get_sub_field('image');
// Image variables
$url = $image['url'];
// Thumbnail size attributes
$size = 'services-image';
$thumb = $image['sizes'][$size];
$width = $image['sizes'][$size . '-width'];
$height = $image['sizes'][$size . '-height'];
?>
<section class="content">
<div class="row">
<div class="columns medium-12">
<ul class="medium-block-grid-4" data-equalizer data-options="equalize_on_stack: true">
<?php
if(have_rows('services_list')):
$count = 0;
while (have_rows('services_list')) : the_row();
$count++;
?>
<li>
<a href="<?php echo get_sub_field('link'); ?>">
<img src="<?php echo get_sub_field('image'); ?>" />
<div class="service_title">
<p><?php echo get_sub_field('text'); ?></p>
</div>
</a>
</li>
<?php
endwhile;
endif;
?>
</ul>
</div>
</div>
</section>
<?php endif; ?>
However, the image path returns 'Array' in the code?
Change in your custom field return format in Image array to Image URL.

how to display each gallery image in category page

i want to make categories gallery. so i have one category called gallery, i create some post with gallery images. in gallery category page i want to display each post 4 picture. picture will take from advancedcustomfields gallery field. bellow is my current category-gallery page code, image not coming but title and more link working fine. would guys tell me what how to do ?
<?php get_header(); ?>
<div class="contentarea">
<div class="wapper">
<div class="content clearfix">
<?php
while ( have_posts() ) :
the_post();
$images = get_field('gallery_picture');
?>
<h2><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></h2>
<img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" /> Gallery </div>
<?php endwhile; ?>
</div>
</div>
</div>
<?php get_footer(); ?>
i solve this problem. so want to share with other. this for category page. bellow is code
<?php
while ( have_posts() ) :
the_post();
?>
<h2><a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a></h2>
<?php
$images = get_field('gallery_picture');
$max = 5;
$i = 0;
if( $images ): ?>
<ul>
<?php foreach( $images as $image ): $i++; ?>
<?php if( $i > $max){ break; } ?>
<li> <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" /> </li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Gallery </div>
<?php endwhile; ?>

WordPress custom post type pagination on Zylyz theme

Sorry for asking in my first question, but I have a big problem with my theme and nobody could solve it. Actually it's so simple:
I am using Zylyz recipe theme. I set the home page to a custom post type (recipes), but as you might guess, when I press the "Older Entries" button it gives "not found" error, because it tries to get ordinary blog posts, not "recipes" (you know, if I had enough blog post it wouldn't give error, but would show posts, not recipes).
So, how can I get rid of this problem?
Thank you very much in advance.
Here's the home page's codes:
<div id="content">
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('post_type=recipes'.'&paged='.$paged);
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="post clearfix" id="post-<?php the_ID(); ?>">
<?php
if ( has_post_thumbnail() ) { ?>
<img class="postimg" src="<?php bloginfo('stylesheet_directory'); ?>/timthumb.php?src=<?php get_image_url(); ?>&h=200&w=200&zc=1" alt="<?php the_title(); ?> Recipe"/>
<?php } else { ?>
<img class="postimg" src="<?php bloginfo('template_directory'); ?>/images/dummy.jpg" alt="" />
<?php } ?>
<div class="cover">
<div class="title">
<h2><?php the_title(); ?></h2>
</div>
<div class="recipemeta">
<span class="cooktime"> <strong>ready in</strong> <?php $cooktime=get_post_meta($post->ID, 'wtf_cooktime', true); echo $cooktime; ?> mins </span> <span class="serve"> <strong>Serving:</strong> <?php $serving=get_post_meta($post->ID, 'wtf_serving', true); echo $serving; ?> people</span>
</div>
<div class="entry" align="justify">
<?php wpe_excerpt('wpe_excerptlength_recipe', ''); ?>
<div class="clear"></div>
</div>
</div>
</div>
<?php endwhile; ?>
<div class="clear"></div>
<?php getpagenavi(); ?>
<?php $wp_query = null; $wp_query = $temp;?>
</div>

How to link image in the article to image itself by default in WordPress

Is there anyway i can set the image link by default to the post itself?
I don't want to set the image link in the media up loader every time.
My code that gets content for post is this:
<?php if (!$is_paged && $archives == "false") { ?>
<?php woo_image('class=thumbnail&width='.get_option('woo_home_thumb_width').'&height='.get_option('woo_home_thumb_height')); ?>
<div class="post-title">
<h3><?php the_title(); ?></h3>
<p class="post-details"><?php _e('Posted on',woothemes); ?> <?php the_time('d. M, Y'); ?> <?php _e('by',woothemes); ?> <?php the_author_posts_link(); ?>.</p>
</div>
<?php } else { ?>
<?php woo_image('class=alignleft thumbnail&width='.get_option('woo_thumb_width').'&height='.get_option('woo_thumb_height')); ?>
<h2><?php the_title(); ?></h2>
<p class="post-details"><?php _e('Posted on',woothemes); ?> <?php the_time('d. M, Y'); ?> <?php _e('by',woothemes); ?> <?php the_author_posts_link(); ?>.</p>
<!-- <div class="comment-cloud">
<?php comments_number('0','1','%'); ?>
</div> -->
<?php } ?> <?php global $more; $more = 0;?>
<?php if ( get_option('woo_content') == "true" ) { the_content('Read More >>'); } else { the_excerpt();?><?php } ?>
</div>
<!-- Normal Post Ends -->
What i do is post an image with some lines below it and the insert a read more tag.
Is there a way i can use first image in the post and link to the article, just as the title does?
At top of the page
<?php
global $post;
global $wpdb;
?>
<a href="<?php echo get_permalink($post->ID); ?>" >
<img src="your_source_here" title="image" />
</a>
get_parmalink(); will take you to the detail page of the post respectively.

Wordpress category template is showing posts from all categories instead of specific category posts

I have an archive page that's set up to display category specific posts. However, instead of showing only the posts from a given category on the category page, it's showing all posts. For an example, see here.
Here's the code I'm using on my archive.php page. I know it's improper use of the loop, but I'm not sure how to fix it. Thanks for the help.
<?php get_header(); ?>
<div id="content">
<div id="inner-content" class="wrap clearfix">
<h1 class="blogTitle" style="margin:10px 0 3px 0;">Blog Title</h1>
<nav class="blogNav" role="navigation">
<?php bones_blog_nav(); // Adjust using Menus in Wordpress Admin ?>
</nav>
<div id="main" class="eightcol first clearfix" role="main">
<div class="catwhiteBg">
<?php if (is_category()) { ?>
<h1 class="catTitle">
<span><?php _e("", "bonestheme"); ?></span> <?php single_cat_title(); ?>
</h1>
<?php echo category_description( $category_id ); ?>
<?php } elseif (is_author()) { ?>
<div class="authorTop">
<?php
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
?>
<div class="author-pic"><?php echo get_avatar( $curauth->user_email, '80' ); ?></div>
<div class="author-name"><span style="font-weight: 200; color: #575757;">POSTS BY:</span>
<?php echo $curauth->first_name; ?> <?php echo $curauth->last_name; ?>
</div>
<div class="author-bio"><?php echo $curauth->description; ?></div>
<div class="author-twitter"><span>twitter</span></div>
</div>
<?php } elseif (is_day()) { ?>
<h1 class="archive-title h2">
<span><?php _e("Daily Archives:", "bonestheme"); ?></span> <?php the_time('l, F j, Y'); ?>
</h1>
<?php } elseif (is_month()) { ?>
<h1 class="archive-title h2">
<span><?php _e("Monthly Archives:", "bonestheme"); ?></span> <?php the_time('F Y'); ?>
</h1>
<?php } elseif (is_year()) { ?>
<h1 class="archive-title h2">
<span><?php _e("Yearly Archives:", "bonestheme"); ?></span> <?php the_time('Y'); ?>
</h1>
<?php } ?>
</div>
<div class="psts">
<?php
global $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
query_posts(array('posts_per_page' => '8','paged'=>$paged));
?>
<?php
$count = 1;
while (have_posts()) : the_post(); ?>
<div class="sixcol small pst<?php if ((isset($count)) && ($count % 2 == 0 )) { echo ' last';} // same logic to add class of last to last item in row of two ?>" id="post-<?php the_ID(); ?>">
<article id="post-<?php the_ID(); ?>" role="article">
<div class="thumb-wrapper mobile">
<?php if(has_post_thumbnail()) { $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'post-thumb' ); echo '<img src="' . $image_src[0] . '" width="100%" class="post-thumb" />'; } ?>
<header class="post-thumb-header">
<h2 class="post-title"><?php the_title(); ?></h2>
</header> <!-- end article header -->
<p class="meta"><?php the_category(', '); ?></p>
</div>
<section class="mobile-content">
<?php the_excerpt(); ?>
</section>
</article> <!-- end article -->
</div>
<?php $count++; ?>
<?php endwhile; ?>
<nav class="wp-prev-next">
<?php echo rb_pagination(); ?>
</nav>
</div> <!-- end .psts -->
</div> <!-- end #main -->
<?php get_sidebar(); // sidebar 1 ?>
</div> <!-- end #inner-content -->
</div> <!-- end #content -->
<?php get_footer(); ?>
I think you're overriding the original query with this line:
query_posts(array('posts_per_page' => '8','paged'=>$paged));
Can you swap this line with this, and let me know the results?
global $query_string;
query_posts( $query_string . "&posts_per_page=8&paged=$paged" );
if that fails try this:
query_posts(array('posts_per_page' => '8','paged'=>$paged, 'cat' => $category_id ));

Resources