How to prevent PHP Code outputting the content in bold? - php

In my WordPress website, I have created a category template file (archive file) for showing all posts from a specific category. The code is working fine and I am getting the exact result what I need. However, there is some problem with my code (which I am unable to investigate).
The template file outputs 5 posts and the content of the first 2 posts is exactly what they are. However, the content of the remaining 3 posts appears in bold, which is strange.
Here is my code:
<section class="video_categories" id="content" style="float:left;">
<?php
$args = array(
'post_type' => 'post',
'category_name' => 'sponsor-spotlight',
'posts_per_page' => -1
);
$obituary_query = new WP_Query($args);
while ($obituary_query->have_posts()) : $obituary_query->the_post();
$readMore = ' Keep On Reading...';
echo '<div class="advert-div" style="padding-bottom: 15px;">'; ?>
<h2 class="ad-title"> <?php echo '<a style="color: #333333;font-weight: 600;" href="' . get_the_permalink() . '">';?> <?php the_title(); echo '</a>'; ?>
</h2>
<?php
$post = get_post( $post->ID );
$content_arr = get_extended($post->post_content);
echo apply_filters('the_content', $content_arr['main']);
echo $readMore;
echo '</div><hr>';
endwhile;
wp_reset_postdata();
?>
</section>
As per my investigation, the problem lies in the following lines of code because it results in outputing <strong> </strong> tags which enclose the content:
$content_arr = get_extended($post->post_content);
echo apply_filters('the_content', $content_arr['main']);
Because when I do:
echo apply_filters('the_content', $post->post_content);
I do not see any <strong></strong> tag on the front end that encloses the content.
Here is the strange output of the code I am using above.
Any help will highly be appreciated!

Although there was no reason for the code to output <strong></strong> tags on the front end, so I practiced #Jayr recommendations by changing the status of each post which was showing in bold. The problem was within the content of those posts. I simply recreated new posts with the same content and my problem was resolved.
Thanks to #Jayr for his quick response!

Related

WordPress Posts from category won't display

I use a plugin called "Custom Content Type Manage"
this allows me to create a new content type which essentially mimics posts (all done in the name of 'user friendly')
This aside, I wrote the following:
<h2><?php single_cat_title( '', true ); ?></h2>
<p>
<?php
$page_id = '5536';
$page_data = get_page($page_id);
print apply_filters('the_content', $page_data->post_content);
?>
</p>
<p>
<?php
$category = get_the_category();
$category_id = $category[0]->cat_ID;
print category_description( $category_id );
?>
</p>
<div class="category-list">
<?php wp_nav_menu(); ?>
</div>
<ul class="leaders-container">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<li class="leader-container">
<?php
$image = get_custom_field('leader_image:to_image_array');
$url = get_custom_field('website_url:raw');
print "<img class='leader-image' src='".$image['0']."'>";
?>
<h2>
<?php the_title(); ?>
</h2>
<?php
print "</h2>";
the_content();
if($url != "#") {
print "<a class='website-button' href='".$url."' target='_blank'>Visit Website</a>";
}
?>
</li>
<?php endwhile; endif;?>
What this was doing, was getting the info from the category, and listing all the posts assigned to the category.
In this case, a post was labeled as a "Leader" and a category was their "congregation", so it was listing all the leaders assigned to the congregations.
This is an example of what it should look like
http://www.ubmsonline.org/?leader=rabbi-binyamin-sheldrake
However, this only works as it is a direct link from the posts in question
The category on the otherhand, which was working, and did list as many leaders assigned to the category, has now stopped working.
http://www.ubmsonline.org/category/ubms-leaders/
As you can see though, its pulling everything across correctly, category description, category title etc, but its just now not showing the posts.
fixed!
It was to do with a setting that changed on the "Custom Content Type Manager" plugin im using. After alot of research, i stumbled upon the exact problem on the "issues" section of the plugin's FAQ's page.
https://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=594
Hopefully this might help others.
In wp-content/plugins/custom-content-type-manager/loader.php the filter mentioned below might be commented, so if you uncomment this add_filter this bug will fix.
// Enable archives for custom post types
add_filter('request', 'CCTM::request_filter');
Thanks again for every one's help.
Andrew

Link is not appearing correct in wordpress

I am trying to get the link from the database in WordPress and user should direct to that link on a single click.
I have almost achieved everything but there is one weird problem I am facing.
In my custom php file I have this code.
<div style =" margin-bottom: 40px; "><div><li><a href="<?php echo $array_var ?>">
<?php echo get_the_post_thumbnail( $post_id, 350,'' ); ?></br><h2><?php the_title(); ?></h2></a><?php echo get_the_excerpt();?></li></div></div>
Here ahref tag is coming as "website custom page link/database-link". Whereas at other places it is coming only as link from the database (which is the correct case for me.)
I will explain it little more.
<?php $query = new WP_Query( array(
'post_type' => 'post',
'category_name' => 'Trending',
'posts_per_page' => 8
) );
$i=0;
while ($query->have_posts()) : $query->the_post();
$post_id= $query->post->ID;
$array_var=$link_array[$i];
**echo $array_var;**
?>
<ul>
<div style =" margin-bottom: 40px; "><div><li>**<a href="<?php echo $array_var ?>">**
<?php echo get_the_post_thumbnail( $post_id, 350,'' ); ?></br><h2><?php the_title(); ?></h2></a><?php echo get_the_excerpt();?></li></div></div>
<?php
$i++;
endwhile; ?>
</ul>
I have marked two places in the code in asterisk. Both have same code but behaviour is different. At first place I am getting link as, say, www.google.com and at second place I am getting it as /www.google.com.
I want it to be www.google.com only.
For reference, the corresponding page is www.coolfuzz.com, you can see that in the first row above every thumbnail is the correct link(which is not clickable btw) but thumbnail has incorrect link.
Please tell me how to correct this?
You should add the http:// to the beginning

Wordpress Double Pages ID inside the Code

I'm working on a theme similar to getBootstrap.com page. The issue I'm facing is:
I'm trying to display specific content in the purple section by using the following:
<?php $recent = new WP_Query("page_id=39"); while($recent->have_posts()) : $recent->the_post();?>
<h1><?php the_title(); ?></h1>
<br>
<div class="col-md-4 col-md-offset-4">
<?php the_content(); ?>
<?php endwhile; ?>
The top content are brought from page ID 39 <-- this is a page template, as I will be creating multiple templates to display specific content at the top from other pages as well, if there is another way please help otherwise...
I also have this code after the top content which is the default content page (The default page content from the WordPress WYSIWYG editor).
<?php the_content(); ?>
But it is getting page ID 39 content.
I want to the page ID I'm in contents at the bottom (white space) beside the page ID 39 in the (purple space).
I hope my question is clear.
http://i.stack.imgur.com/6lspz.png
Solution Found:
<?php
$id=39;
$post = get_post($id);
$content = $post->post_content;
echo $content;
?>
Just Used this:
<?php
$id=39;
$post = get_post($id);
$content = $post->post_content;
echo $content;
?>

How to wrap echo div in <a href>

I'm running into two problems transferring a Wordpress archive page into a page template.
<?php $args = array( 'post_type' => 'casestudies', 'posts_per_page' => 12 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<div class="casestudy">'.get_the_post_thumbnail( $post->ID, '180,180' ).'</div>';
First I need to wrap the echo for the thumbnail with a link in order to trigger a css action:
'<a href="'.the_permalink().'" class="anchor-hover">';
When I add that a href line it only prints the link, and doesn't wrap the echo.
The a href should then print the title and excerpt over the thumbnail box:
'<span class="details"><div class="anchor-hover details-h3"><?php the_title(); ?></div>';
'<p class="desc"><?php echo get_post($post_id)->post_excerpt; ?></p></span></a>';
endwhile; ?>
<div class="clear"></div>
</div></div>
In wordpress, you have two type types of functions. One's that return the results, and one's that echo the results.
You are using the_permalink(); which is already echoing out it's result.
You need to be using get_the_permalink(); since you are trying to echo it in your template.
get_permalink worked for that a href, thank you, but how can I get php the_title() and php echo get_post($post_id)->post_excerpt to show up on the cursor hover?
This code should be working if you are in the loop
LINK
The method get in WordPress will give you the string only.
http://codex.wordpress.org/Function_Reference/get_the_excerpt
http://codex.wordpress.org/Function_Reference/get_the_title

PHP concatenation syntax error when using css for animation effect

In a Wordpress page template I have the following code in an effort to replicate a successful archive page:
<?php $args = array( 'post_type' => 'casestudies', 'posts_per_page' => 12 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<div class="casestudy">'.get_the_post_thumbnail( $post->ID, '180,180' ).'</div>';
echo '<span class="details"><div class="anchor-hover details-h3">'.the_title().'</div>';
echo '<p class="desc">'.get_post($post_id)->post_excerpt.'</p></span>';
endwhile; ?>
<div class="clear"></div>
I need to compress that into only one echo, in order to have the css animation work. I will also need to wrap the entire display starting with "echo" with this div:
<div<?php post_class('margin') ?> id="post-<?php the_ID(); ?>">
The title and excerpt are only supposed to show when the cursor is hovering over the thumbnail, but I can't get this line of code in without an unexpected syntax error.
I am able to get this to work on the archive for this post type so there should be some way to do it.
Am I asking too much of this kind of code? Is there a reason I can get the animation working on the archive page working but not this one? Thanks
you can't double parse php...
echo '<div class="casestudy">'.get_the_post_thumbnail( $post->ID, '180,180' ).'</div>';
should be
echo '<div class="case study">'.get_the_post_thumbnail( $post->ID, '180,180' ).'</div>';
specifically:
<?php the_permalink() ?>
should be
.'the_permalink().'
It might help you to format your code a bit. It looks like there may be problems with single and double quotes, along with PHP tags inside strings. If you are creating large HTML template fragments, you may want to use something like ob_start() and ob_get_clean()
Here's just a quick example using your code:
<?php
$args = array( 'post_type' => 'casestudies', 'posts_per_page' => 12 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) {
$loop->the_post();
ob_start();
?>
<div class="casestudy">
<a href="<?php the_permalink() ?>" class="anchor- hover">
<?php
echo get_the_post_thumbnail( $post->ID, '180,180' );
?>
</a>
</div>
<span class="details">
<div class="anchor-hover details-h3">
<?php
echo the_title();
?>
</div>
<p class="desc">
<?php
echo get_post($post_id)->post_excerpt;
?>
</p>
</span>
<?php
echo ob_get_clean();
}
?>
<div class="clear"></div>
Side note: you probably shouldn't put an inline element (span) inside a block level element (div).

Categories