I am building a child theme using Flaxseed as a parent. This theme includes several 'content styles' which can be selected using Theme > Customizer. Each of these styles has a function in the parent functions.php file that renders the CSS and wordpress content into one. I want to edit some of the Loop functions that are in here, specifically updating the_excerpt to the_content, but I want to do so in a way that works with my child theme.
Since this code is in the parent functions.php, and since the theme customizer calls it specifically by name, I cannot simply add a new function, and I cannot override it using the same function name.
My best guess is that I need to somehow remove this function from the parent functions.php before loading a new function of the same name in my child function.php, but I cannot seem to figure out how.
Below is the code from the template file where the function is loaded into the template:
<?php for ($i = 1; $i < 8; $i++)
if (get_theme_mod('flaxseedpro_fa_'.$i) != 'none') {
flaxseedpro_display_featured_area(
get_theme_mod('flaxseedpro_fa_'.$i),
get_theme_mod('flaxseedpro_fa_title'.$i),
get_theme_mod('flaxseedpro_fa_cat'.$i)
);
}
?>
Here, the $i variable is the value that is set in the Theme > Customizer screen. This file and code could be modified easily as a part of the child theme.
Below are two code snips from the parent functions.php which select the appropriate featured area code:
function flaxseedpro_display_featured_area($style, $fa_title, $cat) {
if (is_home()) :
switch ($style) {
case 'carousel':
flaxseedpro_carousel($fa_title, $cat);
break;
case 'style1':
flaxseedpro_featured_style1($fa_title, $cat);
break;
case 'style2':
flaxseedpro_featured_style2($fa_title, $cat);
break;
case 'style3':
flaxseedpro_featured_style3($fa_title, $cat);
break;
case 'style4':
flaxseedpro_featured_style4($fa_title, $cat);
break;
default:
break;
}
endif;
}
which leads to several functions such as this:
function flaxseedpro_featured_style2($fa_title, $cat) {
?>
<div class="featured-style1 featured-style2">
<?php if ('' !== $fa_title) : ?>
<h2 class="featured-section-title container">
<?php echo esc_html($fa_title); ?>
</h2>
<?php endif; ?>
<div class="featured-posts-inner container">
<?php
$args = array(
'posts_per_page' => 5,
'cat' => $cat,
);
$fa_posts = new WP_Query($args);
if ($fa_posts->have_posts()) :
$counter = 0;
while ($fa_posts->have_posts()) :
$fa_posts->the_post();
$counter++;
if (1 === $counter) {
?>
<div class="feat-col1 md-6 sm-6">
<div class="md-12 pr-0 pl-0">
<article id="post-<?php the_ID(); ?>" <?php post_class('featured-post-item'); ?>>
<div class="item-container mb-3">
<?php if (has_post_thumbnail()) : ?>
<?php the_post_thumbnail('medium-large', array('class' => 'featured-post-thumbnail-primary')); ?>
<?php else : ?>
<img src="<?php echo esc_url(get_template_directory_uri() . '/assets/images/placeholder.png'); ?>">
<?php endif; ?>
</div>
<div class="post-title-parent">
<a class="post-title title-font" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<div class="post-author">
<?php esc_html_e('By', 'flaxseed-pro'); ?> <?php the_author(); ?> <i class="fa fa-clock-o"></i> <?php the_time('F j, Y'); ?>
</div>
<div class="entry-excerpt body-font mb-3"><?php the_excerpt(); ?></div>
</div>
<?php _e('Read More','flaxseed-pro') ?>
</article>
</div>
</div>
<?php
} else {
?>
<div class="feat-col2 md-6 sm-6">
<article id="post-<?php the_ID(); ?>" <?php post_class('featured-post-item'); ?>>
<div class="md-4 xs-4">
<div class="item-container">
<?php if (has_post_thumbnail()) : ?>
<?php the_post_thumbnail('medium', array('class' => 'featured-post-thumbnail-secondary')); ?>
<?php else : ?>
<img src="<?php echo esc_url(get_template_directory_uri() . '/assets/images/placeholder.png'); ?>">
<?php endif; ?>
</div>
</div>
<div class="md-8 xs-8">
<div class="post-title-parent">
<a class="post-title title-font" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<br><small><?php esc_html_e('By', 'flaxseed-pro'); ?> <?php the_author(); ?> <i class="fa fa-clock-o"></i> <?php the_time('F j, Y'); ?></small>
</div>
</div>
</article>
</div>
<?php
}
endwhile;
endif;
wp_reset_postdata();
?>
</div>
</div>
<?php
}
This is the the code I've been trying to override but unable to find a solution as a part of the child theme. All of the answers I've found seem to require a hook, which I cannot discern from this code.
This is solved.
I changed the function name that is called in my template file (flaxseedpro_display_featured_area >> flaxseedpro_display_featured_area2), then redefined the switch function to replace 'style3' with a new 'style5'. Then added the new 'style5' function with updated CSS code.
Related
My 'hero' element is taking most of the top page, and an user would have to manually scroll past it to get to the content.
I want to change it so that clicking the links will scroll past the image and down to the posts title. At the minute, clicking the post reloads the page and the hero element is on top. But if you click 'more' tag, it scrolls nicely.
How do I make it so that clicking the link will scroll the page down in Wordpress? I don't mean 'more' tag. Maybe there is a way to update the link functions in WP so the links will create anchor like 'more' tag?
I haven`t got a code that creates a link, as they are created by WP (they are post links).
<div class="big">
</div>
<article><div class="post">
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
</div></article>
.big {
height: 1200px;
width: 900px;
background-color: grey;
}
JS Fiddle: https://jsfiddle.net/tvue1mwo/
single.php code:
<?php
if (is_single()) {
// Currently using get_header('posts'), so I can hide hero element by css and unhide it with js
get_header('posts');
// If I understand right, here should go the ANCHOR link?
}
else {
// Loads normal hero withou extra css class
get_header();
}
?>
<div class="main-section wrapper">
<?php
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<div class="post-content u-cf">
<h2 class="post"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?></a></h2>
<p class="post-info"><i class="fa fa-folder-open" aria-hidden="true"></i>
<?php
$categories = get_the_category();
$separator = ", ";
$output = '';
if ($categories) {
foreach ($categories as $category) {
$output .= '' . $category->cat_name . '' . $separator;
}
echo trim($output, $separator);
}
?>
|
<i class="fa fa-clock-o" aria-hidden="true"></i> <?php the_time('j/m/Y'); ?>
</p>
<div class="banner-image"><?php the_post_thumbnail('banner-image'); ?></div>
<?php the_content(); ?>
<?php endwhile; ?>
</div>
<?php
else :
echo '<p> No Content found</p>';
endif; ?>
</div>
<?php get_footer(); ?>
index.php:
<?php
if (have_posts()) :?>
<?php $count = 1;
while (have_posts()) : the_post(); ?>
<div class="post-content u-cf">
<?php if (has_post_thumbnail()) {
?>
<div class="post-thumbnail u-cf"><a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('small-thumbnail') ?></a>
</div>
<?php } ?>
<h2 class="post">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
<p class="post-info"><i class="fa fa-folder-open" aria-hidden="true"></i>
<?php
$categories = get_the_category();
$separator = ", ";
$output = '';
if ($categories) {
foreach ($categories as $category) {
$output .= '' . $category->cat_name . '' . $separator;
}
echo trim ($output, $separator);
}
?>
|<i class="fa fa-clock-o" aria-hidden="true"></i> <?php the_time('j/m/Y'); ?>
</p>
<?php the_content(); ?>
<hr>
<?php if ( 2 === $count ) { ?>
<div class="main-content-advert">
<p>Lorem ipsum</p><p>Lorem impsum</p>
</div>
<hr>
<?php }
$count++; ?>
<?php endwhile; ?>
</div>
<?php
else :
echo '<p> No Content found</p>';
endif; ?>
If you are using index.php to display the homepage & archives, you can do the following:
<?php
/* 1. define the name of the anchor to jump to */
$anchorname = "skipheroimage";
$count = 0;
if (have_posts()) :
while (have_posts()) : the_post();
?>
<?php
$count++; /* increment the count so that each anchor is unique on the page */
/* 2. add the anchor to the permalink so it will jump directly to the anchor */
$linkwithanchor = get_permalink()."#".$anchorname.$count;
?>
<div class="post-content u-cf">
/* 3. use our $linkwithanchor variable to create the link */
<h2 class="post"><a href="<?php echo $linkwithanchor; ?>">
<?php the_title(); ?></a></h2>
/* no change to the code that was here, so keep it as it was...
... I just removed it to make my changes easier to find */
<div class="banner-image"><?php the_post_thumbnail('banner-image'); ?></div>
/* 4. add our anchor - this is where the link will jump to */
<a id="<?php echo $anchorname.$count; ?>" name="<?php echo $anchorname.$count; ?>"></a>
<?php the_content(); ?>
</div> /* NOTE - you had this in the wrong place. */
<?php endwhile; ?>
<?php
else :
echo '<p> No Content found</p>';
endif; ?>
This will create an anchor directly after the banner image, and add the anchor name to the link so that it will jump directly to it.
I have commented and numbered each step directly in the code.
You will need to do this for any templates you have that displays the links (e.g. archive.php)
In my theme WordPress to display the post uses this (code #1):
function inner($posts, $td_column_number = '') {
$buffy = '';
if (!empty($posts)) {
foreach ($posts as $post) {
$td_module_17 = new td_module_17($post);
$buffy .= $td_module_17->render($post);
}
}
return $buffy;
}
I need to show posts using this code (code #2):
<?php
$custom_query = new WP_Query('posts_per_page= 5');
while($custom_query->have_posts()):
$custom_query->the_post();
?>
<div class="post-1">
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h3><?php the_title(); ?></h3>
<div class="float-tags">
<div class="bb-td-post-small-box clearfix">
<?php the_tags('','',''); ?>
</div>
</div>
<div class="post-2">
<?php the_content(); ?>
</div>
</div>
</div>
<?php
endwhile;
wp_reset_postdata(); // reset the query
?>
If I insert code #2 into module 17, then the posts are output immediately all in one block, and not one at a time.
Solved a problem. The code was looped. Here is the working code.
<?php
class td_module_17 extends td_module {
function __construct($post) {
//run the parrent constructor
parent::__construct($post);
}
function render($Post = false) {
ob_start();
?>
<div class="post-1">
<div
<?php //post_class(); ?> id="post-<?= $Post->ID; ?>">
<h3><?= $Post->post_title; ?> </h3>
<div class="float-tags">
<div class="bb-td-post-small-box clearfix">
<?php $tags = get_the_tags($Post->ID); ?>
<? foreach ($tags as $tag) : ?>
<?= $tag->name; ?>
<? endforeach; ?>
</div>
</div>
<div class="post-2">
<?= apply_filters('the_content', $Post->post_content); ?>
</div>
</div>
</div>
<?php return ob_get_clean();
}
}
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.
What I want is like this: Click to see the picture
But,at last It came up with like this:
Click to see the picture
(I can't put images, so I put the picture url here!)
Here Is Code In My comment.php Where Show The Comments:
`<?php wp_list_comments('type=comment&callback=comment_activity_list');?>`
and this is the code of function "comment_activity_list" in my function.php:
<?php if (!function_exists("comment_activity_list")){
function comment_activity_list($comment, $args, $depth){
$GLOBALS['comment'] = $comment;
?>
<ol class="clist">
<li id="discussion-<?php comment_ID() ?>" class="discussion">
<div class="discussion-post clearfix">
<div class="gravatar"><?php echo get_avatar( $comment, 45); ?></div>
<div class="block">
<a class="discussion-username"><?php echo get_comment_author_link() ?></a>
<div class="discussion-text">
<?php comment_text()?>
<?php if ($comment->comment_approved == '0') : ?>
<p><em><?php _e('Your comment is awaiting moderation.'); ?></em></p>
<?php endif; ?>
</div>
<!--.discussion-text-->
<div class="discussion-meta">
<?php delete_comment_link($comment->comment_ID,'class="btn red"')?>- <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?> - <?php if(!function_exists('how_long_ago')){comment_date('M d, Y'); } else { echo how_long_ago(get_comment_time('U')); } ?>
</div>
<!--.discussion-meta-->
</div>
<!-- .discussion-post -->
</div>
<!-- .discussion-post -->
</li>
</ol>
<?php
}
}?>
How can I Customize the children comments ? Any one can hepl me?
Thx In Advance!
You can check if a comment is a child by checking the following
<?php if( $comment->comment_parent ) : ?>
// This is a CHILD comment
<?php else: ?>
// This is a NORMAL comment
<?php endif; ?>
Is there a reason why the_author should return an empty string on the first page when the user is not logged in, but return the author name just as it should when more posts are loaded through AJAX ?
The loop is the same in both cases.
Please help me resolve this issue as I'm clueless and I need it fixed ASAP to launch my site.
Here's the whole index.php:
<?php
get_header();
get_sidebar();
?>
<!-- MAIN DIV -->
<div id='content_and_floater'>
<?php get_template_part('social_floater'); ?>
<div id='content'>
<?php get_template_part('loop'); ?>
</div>
</div>
<?php get_template_part('loader'); ?>
<!-- MAIN DIV -->
<?php
get_footer();
?>
And here's how the infinitePaginator calls the loop in functions.php (the function is called when scrolled down to the bottom or the loader link is clicked):
function wp_infinitepaginate(){
$loopFile = $_POST['loop_file'];
$paged = $_POST['page_no'];
$posts_per_page = get_option('posts_per_page');
# Load the posts
query_posts(array('paged' => $paged ));
get_template_part( $loopFile );
exit;
}
You can see the behaviour at test.nowillnoskill.net.
In single posts it's not working either. My guess is that query_posts(array('paged' => $paged )); changed something in the query, but I don't know what is it.
I tried to insert setup_postdata($post); just after the_post() in loop.php as I found that worked for someone, but it doesn't for me.
I also tried to insert
query_posts(array('paged' => 1 ));
before calling the loop file in index.php, but no posts at all were shown.
Here is my loop.php:
<?php while ( have_posts() ) : the_post() ?>
<!-- POST1 -->
<article class='post'>
<header class='post_header'>
<?php
global $current_user;
$current_user = wp_get_current_user();
if (!empty($current_user)) {
$pid = get_the_id();
$uid = $current_user->ID;
$title = (is_favorite($pid, $uid)) ?
'Remove from favorites' :
'Add to favorites';
$trans = (is_favorite($pid, $uid)) ?
'' :
' transparent';
?>
<div>
<h2>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
<?php if (is_user_logged_in()) { ?>
<a title='<?php echo $title ?>' class='post_favorite' href='#' alt='fpid=<?php echo $pid ?>uid=<?php echo $uid ?>'>
<span class='symbol<?php echo $trans ?>'>R</span>
</a>
<?php } ?>
</div>
<div class='post_header_div'>
<strong class='post_category'>
<?php echo get_the_category_list(', '); ?>
</strong>
<strong class='post_author'>
<span class='symbol'>U</span>
<?php the_author(); ?>
</strong>
</div>
<div>
<span class='post_author'>
<?php edit_post_link('[edit]'); ?>
</span>
</div>
<?php } ?>
</header>
<figure class='post_image'>
<!--<img src='design/img/flashkick.png' alt='logo' />-->
<?php the_post_thumbnail(); ?>
</figure>
<div class='post_perex'>
<?php the_content('Read more'); ?>
</div>
<div class='space'></div>
<footer class='post_footer'>
<div class='post_footer_top'>
<div class='post_tags'>
<?php the_tags('', '', ''); ?>
</div>
<div class='post_time'>
<time datetime="<?php the_time('Y-m-d'); ?>" pubdate>
<span class='symbol'>P </span>
<?php relative_post_the_date(); ?>
</time>
</div>
</div>
</footer>
<div class='space'></div>
</article>
<?php endwhile; ?>
Author informations are given by Wordpress in post informations.
Try to do a var_dump on your query_posts result, you should find where the author name is stored, to display it properly.
Can you please show your loop template ? At least the part displaying the author.