How can i not show the_post_thumbnail if post is opened? - php

I try to devolop my own wordpress theme. However i struggle with the following:
I added the loop to my content php and it is loaded by the page php
the template at the home site is the page.php.
the template when i click and load a post with its content is also the page.php
Ok. So now i have enabled thumbnails. But:
The Thumbnails also show up when i click and open the post.
I only want them to show up in the list of posts page, not in the posts itself.
How can i do that?
Please help me
index.php
<?php get_header(); ?>
<div id= "mainandcartwrapper" class="mainandcartwrapper">
<main>
<?php
$path = "C:\wamp64\www\almondo/wp-content/themes/almondotheme/";
$onlytemplate = str_replace($path,"", get_page_template());
echo $onlytemplate;
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php get_template_part("template_parts/content"); ?>
<?php endwhile; else : ?>
<?php get_template_part("template_parts/content","error"); ?>
<?php endif; ?>
</main>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
</div>
</body>
</html>
page.php
<?php get_header(); ?>
<div id= "mainandcartwrapper" class="mainandcartwrapper">
<main>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php
get_template_part("template_parts/content");
?>
<?php endwhile; else : ?>
<?php get_template_part("template_parts/content","error"); ?>
<?php endif; ?>
</main>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
</div>
</body>
</html>
content.php
<article <?php post_class();?>>
<p class="text-l almondo-link">
<a href="<?php the_permalink();?>">
<?php the_title();
?>
<br>
<?php
$path = "C:\wamp64\www\almondo/wp-content/themes/almondotheme/";
$onlytemplate = str_replace($path,"", get_page_template());
echo $onlytemplate;
?>
<p>Veröffentlicht von <?php the_author(); ?> am <?php the_date("d.m.Y"); ?></p>
</a>
</p>
</article>
content_page.php
<article <?php post_class();?> >Statische Seite:
<p class="text-xs">
<?php the_title(); ?>
</p>
</article>
Have a nice Weekend,
Your Alwin

Related

Secondary menu not showing up in wordpress footer

I am a beginner trying to create my own wordpress theme.
I have two nav menus one for the header one for the footer but the secondary one for the footer is not showing up. My code is currently as shown below.
- Functions.php
function base_theme_setup(){
add_theme_support('menus');
register_nav_menu('primary','Primary Header Navigation');
register_nav_menu('secondary','Secondary Footer Navigation');
}
add_action ('init', 'base_theme_setup');
- footer.php
<footer>
<?php wp_nav_menu(array('theme_location'=>'secondary')); ?>
</footer>
<?php wp_footer (); ?>
</body>
</html>
Managed to solve it.
Had some useless undeleted code at the bottom of my index.php. Once deleted the problem went away.
So went from this
<?php
if( have_posts() ):
while( have_posts() ): the_post(); ?>
<h3><?php the_title(); ?>
</h3>
<div class="thumbnail-img"><?php the_post_thumbnail('large'); ?></div>
<p><?php the_content(); ?></p>
<small>Posted on: <?php the_time('F j,Y'); ?> at <?php the_time('g:i a'); ?>, in <?php the_category(); ?></small>
<hr>
<?php endwhile;
endif;
?>
<?php
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile;
?>
<?php get_footer();?>
to this
<?php
if( have_posts() ):
while( have_posts() ): the_post(); ?>
<h3><?php the_title(); ?></h3>
<?php the_post_thumbnail('large'); ?>
<p><?php the_content(); ?></p>
<small>Posted on: <?php the_time('F j,Y'); ?> at <?php the_time('g:i a'); ?>, in <?php the_category();?></small>
<hr>
<?php endwhile;
endif;
?>
<?php get_footer();?>
Thanks for everyones tips!

Getting Wordpress to show message when no posts exist in category

I am trying to get my blog to show a message to visitors when they visit the category main page (ex: www.website.com/category-slug-here/), but can't seem to figure out the Wordpress Loop quite right. Here is what I started with in my theme's index.php file:
get_header(); ?>
<div id="page-wrap" class="blog-page blog-fullwidth container">
<div id="content" class="blog-wrap <?php echo esc_attr($sidebarlayout); ?> columns">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part( 'framework/inc/post-format/entry', get_post_format() ); ?>
<?php endwhile; endif; ?>
<?php get_template_part( 'framework/inc/nav' ); ?>
</div>
<?php if($sidebar != 'no-sidebar'){ ?>
<div id="sidebar" class="<?php echo esc_attr($sidebarorientation); ?> alt">
<?php get_sidebar(); ?>
</div>
<?php } ?>
</div>
<?php get_footer(); ?>
And here is how I tried to alter it:
get_header(); ?>
<div id="page-wrap" class="blog-page blog-fullwidth container">
<div id="content" class="blog-wrap <?php echo esc_attr($sidebarlayout); ?> columns">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part( 'framework/inc/post-format/entry', get_post_format() ); ?>
<?php endwhile; else: ?>
<p>Sorry, looks like this category is empty!</p>
<?php endif; ?>
<?php get_template_part( 'framework/inc/nav' ); ?>
</div>
<?php if($sidebar != 'no-sidebar'){ ?>
<div id="sidebar" class="<?php echo esc_attr($sidebarorientation); ?> alt">
<?php get_sidebar(); ?>
</div>
<?php } ?>
</div>
<?php get_footer(); ?>
However, making this change doesn't seem to yield any results. Am I missing something here? Seems like this should work (but I'm also not a total PHP guru, which is why I came here to consult with the masses). ;)
In wordpress the posts in category are shown in archive.php page .
Try to write the else condition in archive page instead of index.php page

Combining wordpress admin page content with custom template?

Is there a way to combine content from a wordpress page's main textarea with the content in its custom template?
In this case I have a custom template that displays all posts from a single category, but I would also like to have a section that displays what is written in the wordpress admin Page area.
This is how I have the custom template set up to display relevant posts:
<?php query_posts('category_name=baby-coupons'); ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<h2><?php the_title() ;?> <span class="post-date">- <?php the_time('F j, Y'); ?></span></h2>
<div class="row">
<div class="one-third">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
</div>
<div class="two-third last">
<?php the_excerpt() ;?>
</div>
</div><!--/row-->
<hr>
<?php endwhile; ?>
Above this I would like to have the wordpress pages admin area content display, what a user would normally write into the textarea to display on the page, is this possible?
This is what I've come up with:
<?php get_posts(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content() ;?>
<?php endwhile; ?>
<?php query_posts('category_name=baby-coupons'); ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<h2><?php the_title() ;?> <span class="post-date">- <?php the_time('F j, Y'); ?></span></h2>
<div class="row">
<div class="one-third">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
}
?>
</div>
<div class="two-third last">
<?php the_excerpt() ;?>
</div>
</div><!--/row-->
<hr>
<?php endwhile; ?>
Is this acceptable? It's working but I'm not sure how classy it is!

Sticky Post appears twice in homepage loop. Is there a way to make it appear only once?

So in WordPress, if you run the regular loop, Sticky Posts appear twice. Once at the beginning (as desired) and then once in the chronological order among regular posts. Is there a way to make a post sticky and not appear the second time?
Here's the code from the index.php file.
<?php get_header(); ?>
<div id="content">
<div class="sidebar">
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('Default') ) : ?>
<?php endif; ?>
</div>
<div class="textContainer">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post">
<h1><?php the_title(); ?></h1>
<div class="featuredImage">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'main-thumb' ); } ?>
</div>
<div class="readMore">
<?php // the content of the post
the_content('Read More'); ?>
</div>
<div class="comments">
<?php _e('', 'surplus'); ?> <?php comments_popup_link('{0 Comments}', '{1 Comment}', '{% Comments}'); ?>
</div>
</div>
<?php endwhile; endif; ?>
<div class="nav3">
<?php posts_nav_link(); ?>
</div>
<?php get_footer(); ?>
Thank you!
Liz

Output recent Wordpress posts in tables, 2 posts wrapped in tr tag?

I'm designing a custom wordpress theme where I'd like to display the recent posts on the home page horizontally in tables, two posts per row. It would look like this:
http://www.numenfilm.com/preview/issues.php
So I'd like my index.php file to kick out code like this:
<table>
<tr>
<td>
post contents here
</td>
<td>
post contents here
</td>
</tr>
<tr>
<td>
post contents here
</td>
<td>
post contents here
</td>
</tr>
</table>
The table and td tags are easy. The problem I've having is getting the tr tags to wrap around the posts in groups of two.
I found this post elsewhere on stack overflow:
Table, TR each 2 loop, PHP, HTML
The last suggestion seems to be what I'm looking for, but I haven't had any luck integrating it with wordpress. Here's the code from my index.php page:
<?php get_header(); ?>
<div id="main_content">
<h1>Numen News & Blog</h1>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("showposts=5&paged=$paged");
?>
<?php if (!is_single() && !is_page() && !is_front_page()) : ?><h1><?php wp_title(' ', true, 'right'); ?></h1><?php endif; ?>
<?php /* begin the loop */ if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php if (is_page()) : /* show page contents */ ?>
<div class="pagecontent" id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<?php the_content('Read more →'); ?>
<p><?php wp_link_pages('next_or_number=number&pagelink=page %'); ?></p>
<p><?php edit_post_link('Edit', '[ ', ' ]'); ?></p>
</div>
<?php comments_template(); ?>
<?php else : /* show post contents */ ?>
<div class="post" id="post-<?php the_ID(); ?>">
<div class="postcontents">
<?php if (!is_single()) : ?>
<h2><?php the_title(); ?></h2>
<?php else : ?>
<h1><?php the_title(); ?></h1>
<?php endif; ?>
<div class="posted">Posted <?php the_time('F jS, Y') ?> by <?php the_author_link(); ?> </div>
<?php the_content('Read more →'); ?>
<p><?php wp_link_pages('next_or_number=number&pagelink=page %'); ?></p>
</div>
<?php if(is_single) comments_template(); ?>
</div>
<?php endif; /* end if page or post */ ?>
<?php endwhile;/* end the main loop */ ?>
<?php /* post navigation */ ?>
<?php if (is_single()) : ?>
<div class="postnavigation">
<?php previous_post_link('%link', '<span>←</span> Previous post') ?>
<?php next_post_link('%link', 'Next post <span>→</span>') ?>
</div>
<?php endif; ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<div class="postnavigation">
<?php next_posts_link('Older posts <span>→</span>') ?>
<?php previous_posts_link('<span>←</span> Newer posts') ?>
</div>
<?php endif; ?>
<?php endif; /* end if have_posts */ ?>
</div><!--END main_content -->
<?php /* sidebar */ get_sidebar(); ?>
<?php /* footer */ get_footer(); ?>
Any suggestions?
try this code, the main code inside td is omitted for readability. the code I added and you should add are most in dark red color, I am sure you can figure that out.
<table>
<tr>
<?php $counter=1; ?>
<?php while (have_posts()) : the_post(); ?>
<td>
<?php if (is_page()) : /* show page contents */ ?>
:
:
<?php endif; /* end if page or post */ ?>
</td>
<?php if($counter%2==0) echo '</tr><tr>';
$counter++;
?>
<?php endwhile;/* end the main loop */ ?>
</tr>
</table>
Here is the full code from index.php using the solution posted by bingjie2680 above. It works.
<?php get_header(); ?>
<div id="main_content">
<h1>Numen News & Blog</h1>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("showposts=5&paged=$paged");
?>
<?php if (!is_single() && !is_page() && !is_front_page()) : ?><h1><?php wp_title(' ', true, 'right'); ?></h1><?php endif; ?>
<?php /* begin the loop */ if (have_posts()) : ?>
<table>
<tr>
<?php $counter=1; ?>
<?php while (have_posts()) : the_post(); ?>
<td>
<?php if (is_page()) : /* show page contents */ ?>
<div class="pagecontent" id="post-<?php the_ID(); ?>">
<h1><?php the_title(); ?></h1>
<?php the_content('Read more →'); ?>
<p><?php wp_link_pages('next_or_number=number&pagelink=page %'); ?></p>
<p><?php edit_post_link('Edit', '[ ', ' ]'); ?></p>
</div>
<?php comments_template(); ?>
<?php else : /* show post contents */ ?>
<div class="post" id="post-<?php the_ID(); ?>">
<div class="postcontents">
<?php if (!is_single()) : ?>
<h2><?php the_title(); ?></h2>
<?php else : ?>
<h1><?php the_title(); ?></h1>
<?php endif; ?>
<div class="posted">Posted <?php the_time('F jS, Y') ?> by <?php the_author_link(); ?> </div>
<?php the_content('Read more →'); ?>
<p><?php wp_link_pages('next_or_number=number&pagelink=page %'); ?></p>
</div>
<?php if(is_single) comments_template(); ?>
</div>
<?php endif; /* end if page or post */ ?>
</td>
<?php if($counter%2==0) echo '</tr><tr>';
$counter++;
?>
<?php endwhile;/* end the main loop */ ?>
</tr>
</table>
<?php /* post navigation */ ?>
<?php if (is_single()) : ?>
<div class="postnavigation">
<?php previous_post_link('%link', '<span>←</span> Previous post') ?>
<?php next_post_link('%link', 'Next post <span>→</span>') ?>
</div>
<?php endif; ?>
<?php if ( $wp_query->max_num_pages > 1 ) : ?>
<div class="postnavigation">
<?php next_posts_link('Older posts <span>→</span>') ?>
<?php previous_posts_link('<span>←</span> Newer posts') ?>
</div>
<?php endif; ?>
<?php endif; /* end if have_posts */ ?>
</div><!--END main_content -->
<?php /* sidebar */ get_sidebar(); ?>
<?php /* footer */ get_footer(); ?>
Don't use tables.
If you want to continue to write bad markup you need to do something like this.
<table>
//wordpress loop starts ( you left that part out)
<td>
<tr>
<?php the_content('Read more →'); ?>
</tr>
</td>
// loop ends
</table>

Categories