Modifying single.php on child theme "Mikado Newsflash" - php

I have a website with "Mikado Newsflash" theme and a custom child theme. I can add functions on child theme and that, but if I modify single.php I get no results. Even if I delete the code on main theme it still works. Is it being called somewhere else? I've modified core templates such in framework/modules/blog/templates/singles and no result. Any clue on how to override single.php ?
This is the single.php theme file:
<?php
get_header();
newsflash_mikado_get_title();
get_template_part( 'slider' );
if ( have_posts() ) : while ( have_posts() ) : the_post();
//Get blog single type and load proper helper
newsflash_mikado_include_blog_helper_functions( 'singles', 'standard' );
//Action added for applying module specific filters that couldn't be applied on init
do_action( 'newsflash_mikado_blog_single_loaded' );
//Get classes for holder and holder inner
$mkdf_holder_params = newsflash_mikado_get_holder_params_blog();
?>
<div class="<?php echo esc_attr( $mkdf_holder_params['holder'] ); ?>">
<?php do_action( 'newsflash_mikado_after_container_open' ); ?>
<div class="<?php echo esc_attr( $mkdf_holder_params['inner'] ); ?>">
<?php newsflash_mikado_get_blog_single( 'standard' ); ?>
</div>
<?php do_action( 'newsflash_mikado_before_container_close' ); ?>
</div>
<?php endwhile; endif;
get_footer(); ?>

Most of the times, when an edit on a template file doesn't change anything is because you are changing the wrong file.
Add this code to your theme's functions.php file:
functions.php
function cagb_which_template_is_loaded() {
if ( is_super_admin() ) {
$categories = get_the_category();
//$category_id = $categories[0]->cat_ID;
echo '<div style="margin-top:25px;" id="my-debug">';
global $template;
print_r( $template );
echo ' | ' . get_the_ID();
echo ' | ' . $categories;
echo "</div>";
}
}
add_action( 'wp_footer' , 'cagb_which_template_is_loaded');
When logged in, this addon will add extra information at the bottom of the page (for debug), when you load the homepage (or any other page) it will show something like this:
/www/public_html/wp-content/themes/mikado-newsflash/homepage.php
This way you will know which file of your template is loaded, and you now can edit it.

Related

WordPress child theme's template file doesn't have <h1> tag

Pages like author page on our WordPress site are missing tag. Since the pages are being rendered by the default template index.php, I'm looking for a way to add tag in it. Below is index.php. Test code like echo $thumb . $alttext; doesn't seem to work not because the variable doesn't hold any value, but the code itself isn't working.
<?php get_header(); ?>
<div id="main-content">
<div class="container">
<div id="content-area" class="clearfix">
<div id="left-area">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
$post_format = et_pb_post_format(); echo $post_format; ?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'et_pb_post' ); ?>>
<?php
$thumb = '';
$width = (int) apply_filters( 'et_pb_index_blog_image_width', 1080 );
$height = (int) apply_filters( 'et_pb_index_blog_image_height', 675 );
$classtext = 'et_pb_post_main_image';
$titletext = get_the_title();
$alttext = get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true );
$thumbnail = get_thumbnail( $width, $height, $classtext, $alttext, $titletext, false, 'Blogimage' );
$thumb = $thumbnail["thumb"];
echo $thumb . $alttext;
et_divi_post_format_content();
if ( ! in_array( $post_format, array( 'link', 'audio', 'quote' ) ) ) {
if ( 'video' === $post_format && false !== ( $first_video = et_get_first_video() ) ) :
printf(
'<div class="et_main_video_container">
%1$s
</div>',
et_core_esc_previously( $first_video )
);
elseif ( ! in_array( $post_format, array( 'gallery' ) ) && 'on' === et_get_option( 'divi_thumbnails_index', 'on' ) && '' !== $thumb ) : ?>
<a class="entry-featured-image-url" href="<?php the_permalink(); ?>">
<?php print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
</a>
<?php
elseif ( 'gallery' === $post_format ) :
et_pb_gallery_images();
endif;
} ?>
<?php if ( ! in_array( $post_format, array( 'link', 'audio', 'quote' ) ) ) : ?>
<?php if ( ! in_array( $post_format, array( 'link', 'audio' ) ) ) : ?>
<h2 class="entry-title"><?php the_title(); ?></h2>
<?php endif; ?>
<?php
et_divi_post_meta();
if ( 'on' !== et_get_option( 'divi_blog_style', 'false' ) || ( is_search() && ( 'on' === get_post_meta( get_the_ID(), '_et_pb_use_builder', true ) ) ) ) {
truncate_post( 270 );
} else {
the_content();
}
?>
<?php endif; ?>
</article>
<?php
endwhile;
if ( function_exists( 'wp_pagenavi' ) )
wp_pagenavi();
else
get_template_part( 'includes/navigation', 'index' );
else :
get_template_part( 'includes/no-results', 'index' );
endif;
?>
</div>
<?php get_sidebar(); ?>
</div>
</div>
</div>
<?php
get_footer();
I'll try to be a little more précise in my answer that the comment allow me :)
When you want to customize your template or create a custom one, in Wordpress, you have 3 prossibilities :
1 - The WRONG way
You directly edit the templates files in your theme.
Why is this wrong?
Because template, like plugins, are regularely updated, so if you directly edit your template's files, you risk to loose all your customisations when you'll update it.
To avoid this, you can create that we called a "child theme" in Wordpress.
2 - Create a Child theme
Simpliy putting, it is a nice solution to avoid the issue encountered on the point 1 ;)
A child theme inherit of the parent theme's functions and allow you to make some customizations/addition to it without the risk of loosing it (since when you update the parent theme, the child theme isn't touched).
Here is a complete tutorial of the principle:
https://developer.wordpress.org/themes/advanced-topics/child-themes/
Note: imoo this require some level of knowledge in PHP because a wrong change can break you site.
3 - Using a theme builder
This is your case : on your site is installed the theme DIVI which allow you to customize you theme and create custom templates with no (or few at least) skills in developpment required.
This is why it is called a "theme builder".
To name a few : Divi, Elementor, ...
Again in that case you can directly use the main theme or create a child theme (which is highly recommended).
That being said (wrote), to return to your situation, you found out that the file you need to edit is the "index.php".
I doubt that because it seems to be an author page, so more likely "author.php"
Why?
Because in fact, ALL pages are processed by the "index.php" file as it is the central template file, but if a template corresponding to the content type exist in you theme it will be use instead (index.php is just a fallback in case you theme don't include a custom file for any particular case).
See this article for more information about template hierarchy: https://developer.wordpress.org/themes/basics/template-hierarchy/
BUT, since you use a theme builder, you do not need to edit thoses files.
As you are using Divi, I suggest you to watch some tutorials on how the theme builder works in practice.
In short, inside the template builder interface of Divi, you can create template(s), that you can affect to any type of content.
This video should guid you on the right direction:
https://www.elegantthemes.com/documentation/divi/the-divi-theme-builder/
Hope it helps.

Remove ‘category’ from header title on category pages in wordpress

I would like to remove the ‘Category’ from header title text on category pages in wordpress. Have tried several plugins that claim to remove these but don’t seem to work with my version.. (4.9.6)
Here a screenshot of how it looks now:
https://imgur.com/a/E2gdr2l
So would want to have only ‘News’ displayed there. Anyone knows a way of getting rid of the Category before it?
All the best and thanks in advance!
In Magazine Base theme:
The title is added from the file inc/hooks/header-inner-page.php using the function the_archive_title() like
the_archive_title('<h1 class="entry-title">', '</h1>');
to remove Category from the output you need to add the following filter in your functions.php
add_filter( 'get_the_archive_title', function ($title) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = '<span class="vcard">' . get_the_author() . '</span>' ;
}
return $title;
});
Code credit: Here
That would fix the issue.
Just add a line into your functions.php (After WP5.5).
add_filter( 'get_the_archive_title_prefix', '__return_false' );
check in archive.php or category.php
it is loading from here
<h1 class="entry-title">Category: News</h1>
you can check and edit any of the above mentioned files.

Generate ID or class for each title in WordPress theme

So I have the code below for my website in WordPress. Under that it shows the title of the current page for example, mine is "Baby"(in black). So I would like to have a unique class or ID for each title (so I can have a different color for each title instead of black for all) but since they are generated by PHP I do not know to to achieve this. If it was a pure HTML I could just give a class and style it but now I do not have any unique class.
<?php get_header(); ?>
<div class="primary-content">
<?php
// display taxonomy info
themedsgn_biancca_taxonomy_info();
// initiate the blogroll type
$blogroll_type = get_theme_mod( 'themedsgn_setting_archive_layout', 'grid' );
if( have_posts() ) {
echo '<div class="blogroll blogroll-' . $blogroll_type . ' cf">';
while( have_posts() ) {
the_post();
get_template_part( 'content', $blogroll_type );
}
echo '</div>';
// pagination
themedsgn_biancca_post_pagination();
} else {
get_template_part( 'content', 'none' );
}
?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Look in Appearance/Editor, then look for the file called archive.php. Then search for archive-title. It should be in there.

Show featured images of recent posts in Wordpress?

I have created a very simple plugin for my Wordpress site to display links to my most recent posts with the use of a shortcode ([recentposts]). The plugin works so far but I am struggling with finding a way to display the featured image for each post that is called in the <div> tags for each post link.
Can you please advise how I may do this. The code for my plugin is as follows:
<?php
/*
Plugin Name: Blog Display Blocks
Description: Plugin to display blog posts in block with shortcode
Author: Chris Brosnan
*/
function RecentPosts() {
$recent_posts = wp_get_recent_posts(6);
echo '<div class="blog-contain">';
foreach( $recent_posts as $recent ){
echo '<div class="third-box">' . $recent["post_title"].' </div> ';
}
};
echo '</div>';
add_shortcode('recentposts', 'RecentPosts');
register_activation_hook( __FILE__, array( 'Blogdisplay', 'plugin_activation' ) );
register_deactivation_hook( __FILE__, array( 'Blogdisplay', 'plugin_deactivation' ) );
?>
What would I need to do in order to show the featured image alongside the corresponding link for each post that is called?
Through trial and error combined with some further searching I have now found the solution to my question.
<?php
/*
Plugin Name: Blog Display Blocks
Description: Plugin to display blog posts in block with shortcode
Author: Chris Brosnan
*/
add_image_size( 'featured-thumb', 300, 200, true ); // (cropped)
function RecentPosts() {
$rPosts = new WP_Query();
$rPosts->query('showposts=6');
while ($rPosts->have_posts()) : $rPosts->the_post(); ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'featured-thumb' ); ?>
<?php $image_url = $image[0]; ?>
<a href="<?php the_permalink(); ?>">
<div class="third-box" style="background-image: url(<?php echo $image_url; ?>);">
<p><?php the_title();?></p>
</div>
</a>
<?php endwhile;
wp_reset_query();
};
add_shortcode('recentposts', 'RecentPosts');
register_activation_hook( __FILE__, array( 'Blogdisplay', 'plugin_activation' ) );
register_deactivation_hook( __FILE__, array( 'Blogdisplay', 'plugin_deactivation' ) );
?>
Within your code by using wp_get_recent_posts() you will get the post id($recent["ID"]), then you can use any one of following,
just add this in your code where you want to show the featured image.
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $recent["ID"] ), 'single-post-thumbnail' );
or can use
echo get_the_post_thumbnail($recent["ID"], 'featured-image');

read more link only when excerpt of content is available in wordpress

i am working on a homepage which includes post, sometimes the post is only with featured image and no content, and sometime there is post with both featured image and content. i want to show excerpt with the post with a readmore button when there is content available with the post. i have added a read more button but it even shows with the post which don't have any content. how can i show it only when there is excerpt available for content. here is the code for the excerpt div.
<div class="entry-excerpt">
<?php
if( strlen( $post -> post_excerpt . $post -> post_content ) > 0 ){
?>
<div class="excerpt">
<?php
if( is_user_logged_in () ){
the_excerpt();
echo 'Continue Reading';
}else{
$meta = meta::get_meta( $post -> ID , 'settings' );
if( isset( $meta['safe'] ) ){
if( !meta::logic( $post , 'settings' , 'safe' ) ){
the_excerpt();
echo 'Continue Reading';
}
}else{
the_excerpt();
}
}
?>
</div>
<?php
}
?>
</div>
the question is solved...
here if anyone want to need it in future.
just add this code in functions.php
<?php
function new_excerpt_more($more) {
global $post;
return '<a class="moretag" href="'. get_permalink($post->ID) . '"> Read the full article...</a>'; } add_filter('excerpt_more', 'new_excerpt_more'); ?>
<?php the_content( $more_link_text , $strip_teaser ); ?>
The $more_link_text sets the link text like "Read More". The second one, $strip_teaser, sets whether or not the "more" link should be hidden (TRUE) or displayed (FALSE). The default is FALSE, which shows the link text.
Source

Categories