Removing feature image from Wordpress post. (Dynamic News lite) - php

I want my feature image to stop appearing on the post, I simply want to use it as thumbnail on recent post.
before asking here I tried a lots of different solutions.
I look for the responsible code in single.php but it was not there,
I try to hide my feature image with CSS, when I check my site with firebug I notice that my CSS got overwritten by the orginal CSS, which does not happen normally.
After going through my code, I found this in template-tags.php
// Display Custom Header
if ( ! function_exists( 'dynamicnews_display_custom_header' ) ):
function dynamicnews_display_custom_header() {
// Check if page is displayed and featured header image is used
if( is_page() && has_post_thumbnail() ) :
?>
<div id="custom-header" class="featured-image-header">
<?php the_post_thumbnail('custom_header_image'); ?>
</div>
<?php
// Check if there is a custom header image
elseif( get_header_image() ) :
?>
<div id="custom-header">
<img src="<?php echo get_header_image(); ?>" />
</div>
<?php
endif;
}
endif;
// Display Postmeta Data
if ( ! function_exists( 'dynamicnews_display_postmeta' ) ):
function dynamicnews_display_postmeta() {
// Get Theme Options from Database
$theme_options = dynamicnews_theme_options();
// Display Date unless user has deactivated it via settings
if ( isset($theme_options['meta_date']) and $theme_options['meta_date'] == true ) : ?>
<span class="meta-date sep">
<?php printf(__('<time class="entry-date published updated" datetime="%3$s">%4$s</time>', 'dynamicnewslite'),
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() )
);
?>
</span>
<?php endif;
I tried to remove some part of the code here, since I don't know anything about php, I get lots of error, I am hoping may be you guys can help me.
I am using the theme dynamic news lite.
here is the link to my site http://www.coolstuffgift.com/awesome-birthday-gifts-for-awesome-people/
Original code of Single.php
<?php get_header(); ?>
<div id="wrap" class="container clearfix">
<section id="content" class="primary" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post();
get_template_part( 'content', 'single' );
endwhile;
endif; ?>
<?php comments_template(); ?>
</section>
<?php get_sidebar(); ?>
</div>
This is all I got in single.php
I think the developer did some trick to hide the code.

In your content.php OR content-single.php file.
Just comment the_post_thumbnail() this type of function.

Related

Variable/Code to use in template so content of the page shows at the spot

Learning some wordpress, creating my first custom wordpress site. I created template for my home page and then I want to create one template for a good bunch of sub pages. So I created a file page-sub.php. In pages I can see this template, so I assigned it to my sub pages. But I'm missing the code/variable to show the content of the page that uses the template. Can you guys advise what do I need? Below is my code in the template so far.
<?php
/*
Template Name: Sub Page Template
*/
get_header();
?>
<div class="main">
<div class="container">
<?php
if ( is_singular() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
endif;
the_content();
?>
</div>
</div>
<?php
get_footer();
?>
I think you need to use the Wordpress Post loop.
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
// Post Content here
//
} // end while
} ?>
Perhaps this is what you're looking for.
https://codex.wordpress.org/The_Loop
As far as your code goes I might try to make you html outside the php
for example to do what I think you want to do is this.
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php the_content(); ?>
}
} ?>
I am not 100% on why you are using the singular if statement. Is there something specific you want to do with that?
Something like this?
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
if ( is_singular() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
endif;
the_content();
}
}
?>

WordPress: get_permalink() doesn't take me from the excerpt to the full post

If one day someone else is looking at this in the future with the same problem, here is an update:
UPDATE: Okay, you need to create a single.php and put the loop in that with the_content();
I have a problem here and hopefully it is something small that I over looked.
What I want:
I want only an excerpt of a post to be displayed with a link underneath in WordPress. When I click on the link I want it to show me the full post.
What I tried:
I looked at the WordPress Codex to find out how to do this and read to put this code into my file:
Read More...
or
function new_excerpt_more( $more ) {
return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) .
'">' . __('Read More', 'your-text-domain') . '</a>';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );
What happens:
A link will appear under the excerpt however when I click on it I am taken to a page with just an excerpt rather than the full post.
My request:
What change would I have to make to have the permalink take me to the full post? Below is a list of my code from content.php
<?php
if (have_posts()) :
while ( have_posts() ) : the_post();
?>
<p style="color:white"><?php the_title(); ?></p>
<div class="postContent" style="align:center;">
<?php the_excerpt(); ?>
Read More...
</div>
<?php
endwhile;
else :
?>
<p>Sorry no posts matched your criteria.</p>
<?php
endif;?>
get_permalink() always send you to full post detail page. -> in your case may be you have edited page.php, single.php or function.php to display content limit. -> or check your theme options area for the content limit option if you are using any purchased theme.
I have facing the same issue and I used the below code and it works prefectly fine for me.
function custom_excerpt_more( $more ) {
return sprintf( '<br /><a class="read-more" href="%1$s">%2$s</a>',
get_permalink( get_the_ID() ),
__( 'Read More >>', 'textdomain' )
);
}
add_filter( 'excerpt_more', 'custom_excerpt_more' );
You can try this edited code
<?php
if (have_posts()) :
while ( have_posts() ) : the_post();
?>
<p style="color:white"><?php the_title(); ?></p>
<div class="postContent" style="align:center;">
<?php the_excerpt(); ?>
Read More...
</div>
<?php
endwhile;
else :
?>
<p>Sorry no posts matched your criteria.</p>
<?php
endif;?>

How to move the featured image below the title in Marketify single post

I'm trying to move the post's featured image below the post title in the Marketify theme, however I can't seem to find this hidden in the code.
Can anybody please help me find the code for the post's featured image? How do I move this below the post title?
Firstly, create a Child Theme for your WordPress Theme.
Then look in '/wp-content/themes/[theme-name], where you should find a file entitled 'single.php'. Copy this into your child theme, taking care to ensure you replicate the same directory hierarchy. The 'single.php' is usually the name of your default Blog Post Template.
Open up the 'single.php' file, which you have saved within your child theme, with a programme such as Notepad++ (Notepad will also do but is not as easy on the eye).
You should see something like:
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
}?>
<?php
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1> //This is the title of your Blog Post.
<div class="entry">
<?php the_content(); ?> //This is the content of your Blog Post.
</div>
<?php endwhile; ?>
<?php endif; ?>
There will be a slight variation in the coding but what you are looking to do is highlight:
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
}?>
and then move this coding to beneath <h1><?php the_title(); ?></h1>. You will need to play around as to where exactly you will need it but I hope this helps get you started.
The reason I have suggested that you do this within a Child Theme is that when the Theme Developer rolls out an update, it will delete any modifications you have made within the parent files.
Good Luck!
Thanks for your comment. I assumed it would be similar to code you've written too, but the title and featured image are hidden in the "do_action( 'marketify_entry_before' );".
get_header(); ?>
<?php do_action( 'marketify_entry_before' ); ?>
<div class="container">
<div id="content" class="site-content row">
<div role="main" id="primary" class="col-xs-12 col-md-8 <?php echo ! is_active_sidebar( 'sidebar-1' ) ? 'col-md-offset-2' : '' ?>">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'single' ); ?>
<?php comments_template(); ?>
<?php endwhile; ?>
None the less, for anyone else with the same problem; I figured out how to hide this section in css like so...
.single .header-outer.has-image .page-header {
display: none;
}
And then could use the standard Wordpress functions to make the title and featured image appear where I wanted.
Thanks :)
Tom

different widgets for different pages and posts

my blog page in Wordpress is using a specific widget but I wanted to use different widget for a post in the blog.
I used an example (https://gist.github.com/anonymous/1308851) to write my code in sidebar.php.
<?php
if ( 'content' != $current_layout ) :
?>
<?php
//for rest of posts
if (is_active_sidebar('blog_widget_area') ) : ?>
<div id="secondary" class="blog_widget_area bordered" role="complementary">
<?php dynamic_sidebar( 'blog_widget_area' ); ?>
</div><!-- #secondary .widget-area -->
<?php endif;
//for specific post "Loyalty Program Trends in the Restaurant Industry"
if (is_active_sidebar('loyalty_programs_widget_area') && is_single('4063') ) : ?>
<div id="secondary" class="blog_widget_area bordered" role="complementary">
<?php dynamic_sidebar( 'loyalty_programs_widget_area' ); ?>
</div>
<?php endif;
?>
<?php endif; ?>
However, I couldn't get the second widget to display in that specific post....
Possible solutions:
Before trying below solution make sure some data/widget already loading on sideabar
loyalty_programs_widget_area.
solution 1
// use array inside is_single function
<?php if (is_active_sidebar('loyalty_programs_widget_area') &&
is_single( array('4063','4063-page-name-here') ) ) : ?>
<?php endif; ?>
solution 2
// put separate if check inside sidebar
<?php if (is_active_sidebar('loyalty_programs_widget_area') ) : ?>
if( is_single('4063') ) { } or
if( is_single(array('4063','pagename')) ) { }
<?php endif; ?>
Other possible solutions:
Try:
-deactivating ALL plugins temporarily to narrow down and possibly fix the problem . If the problem goes away, activate them individually to find the culprit?
-switching to the default theme (Twenty Ten) for a moment by renaming your current theme's folder in wp-content/themes. The idea is to force WordPress to fall back to the default theme to rule out any theme-specific issue?
For further details read official documentation regarding " sidebar "
Note:
is_single() offer different other ways to check post id or name(when permalink isenabled)
- is_single(array(17,'beef-stew','Irish Stew'));
- is_single('17'); or is_single(17);
Try this code below:
<?php // only show on 31 post not any other. ?>
<?php if ( is_single('31') ) { ?>
<?php // if blog_widget_area2 is active then show otherwise don't :) ?>
<?php if ( is_active_sidebar( 'blog_widget_area2' ) ) : ?>
<div class="template_2_widget_area bordered">
<?php dynamic_sidebar("blog_widget_area2"); ?>
</div>
<?php endif; ?>
<?php }else{ // otherwise load this sidebar ?>
<div class="template_2_widget_area bordered">
<?php dynamic_sidebar("blog_widget_area"); ?>
</div>
<?php } ?>
With the help of codewizz (Thanks codewizz!), we got it to work. The things we need to change is to move the code over from sidebar.php to single.php. However, the way it's coded, it displays both the first widget and the second widget on the post's sidebar.
So he suggested that I use http://wordpress.org/plugins/display-widgets/. And now it works.
Additionally, if one want to start from scratch, you should use that code
<?php // only show on 31 post not any other. ?>
<?php if ( is_single('31') ) { ?>
<?php // if blog_widget_area2 is active then show otherwise don't :) ?>
<?php if ( is_active_sidebar( 'blog_widget_area2' ) ) : ?>
<div class="template_2_widget_area bordered">
<?php dynamic_sidebar("blog_widget_area2"); ?>
</div>
<?php endif; ?>
<?php }else{ // otherwise load this sidebar ?>
<div class="template_2_widget_area bordered">
<?php dynamic_sidebar("blog_widget_area"); ?>
</div>
<?php } ?>

Wordpress specific content

Good day to all,
I'm new in wordpress. I want to ask on how to display my page content in different div. But when I try this code. It won't display anything, my page won't even load. Any help would be much appreciated. Thanks!
<?php if($_SERVER['REQUEST_URI'] == '/wordpress/?page_id=5'): ?>
<div style="width:960px; float:left;min-height:290px;word-wrap: break-word">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endwhile; // end of the loop. ?>
</div>
<?php else: ?>
<div style="width:640px; float:left;min-height:290px;word-wrap: break-word">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endwhile; // end of the loop. ?>
</div>
<?php endif;?>
If you have access to the theme files, copy and paste the page.php, rename the duplicate file to page-about.php, where about is the slug of the page. Similarly you can have any number of page duplicates.
To find what is the slug of a page, go to the page editing area, Screen Option > View Slug.

Categories