On my main page, I have posts that underneath have the author name. Or well, should. However nothing actually appears and I'm not sure why they aren't showing. On my sidebar.php they do show up. I've tried to see if there was actually something appearing and not being hidden by CSS, however nothing appears at ALL from the get_the_author() on the front-page
Heres my front page code:
$result = wp_get_recent_posts(array(
'numberposts' => 1,
'category' => '',
'post_status' => 'publish',
));
foreach( $result as $p ){
?>
<!-- The card itself-->
<div class="card cardcustom">
<!-- The image -->
<img class="card-img tinted" src="<?php echo get_the_post_thumbnail_url($p['ID'], array(1438, 500)); ?>" style="height: 500px; object-fit: cover; border-radius: 0px;"/>
<!-- Text over the image -->
<div class="card-img-overlay card-content">
<p href="#" class="card-text the-badge badge badge-primary"><?php
foreach(get_the_category($p['ID']) as $category) {
echo $category->name . ' ';
}
?></p><br>
<p class="posttitle card-text" style="font-weight: 600; font-size: 16px;">
<?php echo $p['post_title']?></p><br />
<?php
$authorname = get_the_author();
echo '<p class="authortext card-text">From ' . '<strong class="colorauthor">' . $authorname . '</strong>' . '</p>';
?>
</div>
</div>
<?php
}
?>
And here is the code on my sidebar:
$result = wp_get_recent_posts(array(
'numberposts' => 8,
'category' => '',
'post_status' => 'publish',
));
foreach( $result as $p ){
?>
<!-- The card itself-->
<div class="card cardcustom">
<!-- The image -->
<img class="card-img tinted" src="<?php echo get_the_post_thumbnail_url($p['ID'], array(440, 240)); ?>" style="border-radius: 0px;"/>
<!-- Text over the image -->
<div class="card-img-overlay card-content">
<p href="#" class="card-text the-badge badge badge-primary" style="border-radius: 0px;"><?php
foreach(get_the_category($p['ID']) as $category) {
echo $category->name . ' ';
}
?></p><br>
<p class="posttitle card-text" style="font-weight: 600; font-size: 16px;">
<?php echo $p['post_title']?></p><br />
<?php
$authorname = get_the_author();
echo '<p class="authortext card-text">From ' . '<strong class="colorauthor">' . $authorname . '</strong>' . '</p>';
?>
</div>
</div>
<?php
}
?>
They're almost identical but for whatever reason it refuses to show up on the main page. You can see what I mean from the screenshots below:
MAIN PAGE:
https://gyazo.com/947f49090fd90a4068725a3968e1e205
SIDEBAR ON A DIFFERENT PAGE:
https://gyazo.com/b9325be19f388dc2d64ae2fe502e3ba4
get_the_author() uses the global $authordata.
And wp_get_recent_posts() doesn't alter the main query (because it uses get_posts() under the hood).
I guess on that sidebar it loads the author of the current page. To verify create another page with another user and try to see if the author changes.
I would suggest you get the author name by get_the_author_meta('display_name', $p->post_author); (replace get_the_author_meta with the_author_meta for simply displaying it).
Related
I have duilt a custom post type and added it to a tab on the profile page. I want to add a button to delete the post if the post author is logged in. I tried several methods but couldn't find a way to delete it since I am not trying to delete it from the single post page. Can anyone direct me on how to achieve this?
//function to print publish button
function show_publish_button(){
Global $post;
//only print fi admin
echo '<form id="myForm" name="front_end_publish" method="POST" action="">
<input type="hidden" name="pid" id="pid" value="'.$post->ID.'">
<button type="submit" name="submit" id="submit" value="delete" class="btn" style="margin-left:2px;background:#f5f5f5;"><i class="fa fa-fw fa-times"></i>delete</button>
</form>';}
// Adding Manage Event TAB content
function manage_events_content() {
$type = 'events';
$args = array (
'post_type' => $type,
'name' => $title,
'author' => bp_displayed_user_id(),
'post_status' => 'publish',
'paged' => $paged,
'posts_per_page' => 10,
'ignore_sticky_posts'=> 1,
);
$temp = $wp_query; // assign ordinal query to temp variable for later use
$wp_query = null;
$wp_query = new WP_Query($args);
if ( $wp_query->have_posts() ) :
while ( $wp_query->have_posts() ) : $wp_query->the_post();
echo '<div style="background-color:#fff; padding: 20px; border-radius: 10px; margin: 20px">
<div>
<div>
<h4 style="font-weight: 400; font-size: 15px; text-transform: capitalize">Event Name:
<a style="color:#5a5a5a;" href="' . get_the_permalink() . '">' . get_the_title() . '</a>
</h4></div>
<div>
<h4>
Number of tickets available: <span>' . get_post_meta(get_the_ID(), "number-of-ticket-available", true) . '</span>
</h4>
<h4>
Number of tickets available: <span>' . get_post_meta(get_the_ID(), "number-of-confirmed-attendees", true) . '</span>
</h4>
</div>
<div>
<h4>
Start Date: <span>' . get_post_meta(get_the_ID(), "event-anfang", true) . '</span>
</h4>
<h4>
End Date: <span>' . get_post_meta(get_the_ID(), "event-ende", true) . '</span>
</h4>
</div>' . show_publish_button() . '
</div>
</div>';
endwhile;
else :
echo '<h4>You dont have any events</h4>';
endif;
$wp_query = $temp;
}
i'm developing a real estate page, you can check it out here. As you can see, the page take some time to load, because it loads all the 50 apartments/houses at once.
To speed up the page, i want to know if there is any way to delay the load, so the page load faster.
Here is the loop code, i'm wondering what could work, for example if i put some "if/else" condition before the wordpress make a loop (while ( $newsLoop->have_posts() ) : $newsLoop->the_post();?>), but i don't know how to do it. The ideal for me is that the contents are loaded 3 on 3, or "row by row", once a row have 3 apartments.
<div class="portfolio-items2">
<?php
$newsArgs = array(
'post_type' => 'property',
"orderby" => 'meta_value_num',
"meta_key" => 'numerooff',
"order" => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'property-status',
'field' => 'slug',
'terms' => 'oneoff',
)
)
);
$newsLoop = new WP_Query( $newsArgs );
while ( $newsLoop->have_posts() ) : $newsLoop->the_post();?>
<div class="col-md-4 shortcode-col listing_wrapper <?php meta('seletoroff');?>" >
<div class="property_listing" data-link="http://www.onecia.com.br/imoveis-de-luxo/<?php /* Property ID if exists */ $property_id = get_post_meta($post->ID, 'REAL_HOMES_property_id', true); if(!empty($property_id)){ echo ''.$property_id; }?>">
<div class="listing-unit-img-wrapper">
<div class="property_media"> </div>
<a href="http://www.onecia.com.br/imoveis-de-luxo/<?php /* Property ID if exists */ $property_id = get_post_meta($post->ID, 'REAL_HOMES_property_id', true); if(!empty($property_id)){ echo ''.$property_id; }?>">
<img width="525" height="350" src="<?php meta('imagemoff');?>" class="lazyload img-responsive wp-post-image" alt="" sizes="(max-width: 525px) 100vw, 525px" />
</a>
<div class="tag-wrapper"><div class="featured_div"><?php meta('porcentooff');?></div></div>
</div>
<h4>
<a href="http://www.onecia.com.br/imoveis-de-luxo/<?php /* Property ID if exists */ $property_id = get_post_meta($post->ID,'REAL_HOMES_property_id', true); if(!empty($property_id)){ echo ''.$property_id; }?>">
<?php meta('titulooff');?>
</a>
</h4>
<div class="property_location_image">
<a href="http://www.onecia.com.br/imoveis-de-luxo/<?php /* Property ID if exists */ $property_id = get_post_meta($post->ID,'REAL_HOMES_property_id', true); if(!empty($property_id)){ echo ''.$property_id; }?>" rel="tag">
<span style="font-size: 15px;"><?php meta('bairrooff');?> </span>
</a>
</div>
<br>
<div class="property_listing_details">
<?php
$post_meta_data = get_post_custom($post->ID);
if( !empty($post_meta_data['REAL_HOMES_property_size'][0]) ) {
$prop_size = $post_meta_data['REAL_HOMES_property_size'][0];
echo '<div class="inforoom">'. $prop_size .'m² <div class="info_labels"><img src="http://www.onecia.com.br/wp-content/themes/site2016/images/icon-size.png" style="max-width: 14%; height: auto;"></div></div>';
}
if( !empty($post_meta_data['REAL_HOMES_property_bedrooms'][0]) ) {
$prop_bedrooms = floatval($post_meta_data['REAL_HOMES_property_bedrooms'][0]);
$bedrooms_label = ($prop_bedrooms > 1)? __('Bedrooms','framework' ): __('Bedroom','framework');
echo '<div class="infobath">'. $prop_bedrooms .'<div class="info_labels"><img src="http://www.onecia.com.br/wp-content/themes/site2016/images/icon-bed.png" style="max-width: 17%; height: auto;"></div></div>';
}
if( !empty($post_meta_data['REAL_HOMES_property_bathrooms'][0]) ) {
$prop_bathrooms = floatval($post_meta_data['REAL_HOMES_property_bathrooms'][0]);
$bathrooms_label = ($prop_bathrooms > 1)?__('Bathrooms','framework' ): __('Bathroom','framework');
echo '<div class="infosize">'. $prop_bathrooms .'<div class="info_labels"><img src="http://www.onecia.com.br/wp-content/themes/site2016/images/icon-bath.png" style="max-width: 17%; height: auto;">
</div></div>';
}
?>
</div>
<div class="listing_unit_price_wrapper">
<span class="price_label price_label_before" style="text-decoration: line-through;">De: R$ <?php meta('valordeoff');?></span><br>
<span style="text-decoration: underline; font-size: 22px; font-weight: bold;">Por: R$ <?php meta('valoroff');?> </span>
<span class="price_label"></span>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
I've already installed some plugins, but none of them worked.
I created a notification area for my application. And I would like to display a small red bullet on the right of each tab.
I worked with a position absolute, the thing is now the bullets appear on all the page.
Here is my code and my CSS:
.read-button{
font-size: 8px;
color: #FC5D5D;
display:block;
position:absolute;
right:20px;
padding-top: 15px;
}
And my PHP:
<?php foreach($messages as $mess) { ?>
<?php
$from_user = $user->isClient()?User::findIdentity($mess->message_filmmaker_id):User::findIdentity($mess->message_client_id);
$from_name = $from_user->first_name." ".$from_user->last_name;
$url = "#";
if ($user->isClient()) $url = Url::to(['client/view-project', 'project_id' => $mess->project_id, 'filmmaker_id' => $from_user->id]);
elseif ($user->isFilmmaker()) $url = Url::to(['filmmaker/view-project', 'project_id' => $mess->project_id]);
?>
<a class="content" href="<?= $url ?>">
<div class="notification-item">
<div class="item-pic float-left"><div class="avatar"><?= Html::img(['/site/get-avatar', 'user_id' => $from_user->id]) ?></div></div>
<div class="item-info float-left">
<div><?= $from_name ?> - Il y a <?= $mess->getElapsedTime() ?></div>
<div><?= $mess->message_text ?></div>
</div>
<div class="read-button float-right">
<span class="glyphicon glyphicon-cd" aria-hidden="true"></span>
</div>
<div class="clear-both"></div>
</div>
</a>
<li class="divider"></li>
<?php } ?>
Absolute position works with a parent with absolute or relative position.
Try to set position:relative to notification-item class and absolute position works relative to this parent element.
I'm retrieving data out of a database using PHP's PDO extension. I never had a problem with this and it always shows up in all browsers. BUT when I tested the website on a friends laptop, the foreach loop works but the content is not displayed. The content is present in the source code.
this is how I set up the code that should be displayed:
<?php
foreach($advertentiesManager->recenteAdvertenties() as $advertentie) {
$verkoperData = $usersManager->userData($advertentie->verkoper);
?>
<div class="col-md-4" style="margin:10px 0;">
<div class="advertentie">
<div class="overlay"></div>
<div class="img" style="background:url('images/categorie/<?php echo $advertentie->categorie; ?>.jpg') no-repeat center center;background-size:cover;"></div>
<div class="picture" style="background:url('<?php echo str_replace("../", "", $verkoperData->foto); ?>') no-repeat center center;background-size:cover;"></div>
<div class="prijs"><p class="h2"> <?php echo $advertentie->verkoopprijs; ?></p></div>
<div style="padding: 10px;padding-left:80px;margin-top:-40px;">
<a href="<?php echo $advertentie->type.'/'.strtolower(str_replace(" ", "-", $advertentie->titel)).'-'.$advertentie->id; ?>">
<?php echo $advertentie->titel; ?>
</a>
<br>
<p style="color:#777;font-size:.9em;">
<?php
$beschrijving = strip_tags($advertentie->omschrijving);
$max_length = 100;
if (strlen($beschrijving) > $max_length) {
$offset = ($max_length - 3) - strlen($beschrijving);
$beschrijving = substr($beschrijving, 0, strrpos($beschrijving, ' ', $offset)) . '... Meer';
} else {
$beschrijving = $advertentie->omschrijving;
}
echo $beschrijving;
?>
</p>
</div>
</div>
</div>
<?php
}
?>
You can view a live example at http://www.coupontrade.nl/ the content should be displayed under "Recente advertenties" and above the twitter part.
EDIT 01-28-13: Revised to clarify my question.
I'm using Magento 1.7.0.0 and FishPig WP full integration. We have successfully listed products from specific category and from all categories but was wondering if we can exclude in some cases from specified category. I found solutions to do this in functions.php within WordPress but this does not seem to work.
Here is the current code that displays posts from all categories. We'd like to add an exception so WordPress 1 Category can be excluded.
Here is the code that displays from all categories which I'd like to NOT include category "Press_HomePage":
$col_posts = Mage::getResourceModel('wordpress/post_collection')->addIsPublishedFilter();
$posttotal = count($col_posts->getAllIds());
$posttotid = $col_posts->getAllIds();
//i<=2 means displays last 2 posts
//display latest 2 posts...
for ( $i=1; $i<=2; $i++ )
{
?>
<div class="blog">
<h2><?php echo $col_posts->getItemById($posttotid[$posttotal-$i])->getPostDate(); ?></h2>
<h1><?php echo $col_posts->getItemById($posttotid[$posttotal-$i])->getPostTitle(); ?></h1>
<div style="float:left; margin-top:15px; margin-bottom:25px;">
<?php
$featured_img = $this->getSkinUrl('images/pree_emty.png');
if($featuredImage = $col_posts->getItemById($posttotid[$posttotal-$i])->getFeaturedImage())
{
$featured_img = $featuredImage->getAvailableImage();
}
?>
<img style="float: left;" src="<?php echo $featured_img; ?>" width="204" height="204" alt="" />
<div style="float: left; width: 580px; padding: 10px;">
<p><?php echo substr(strip_tags($col_posts->getItemById($posttotid[$posttotal-$i])->getPostContent()), 0, 400); ?></p>
<p>
<a href="<?php echo $col_posts->getItemById($posttotid[$posttotal-$i])->getUrl(); ?>">
<img src="<?php echo $this->getSkinUrl('images/view_btn.jpg'); ?>" width="170" height="32" alt="" />
</a>
</p>
</div>
</div>
</div>
<?php
}
?>
Let me know if I need to clarify myself. I appreciate your time.
//loki - get all the post ids
$col_posts = Mage::getResourceModel('wordpress/post_collection')->addIsPublishedFilter();
$posttotid = $col_posts->getAllIds();
//loki - get all the press ids
$col_posts_press = Mage::getResourceModel('wordpress/post_collection')->addIsPublishedFilter()->addCategorySlugFilter('press_homepage');
$posttotid_press = $col_posts_press->getAllIds();
//loki - removing the press_homepage category from array and reindexing
$blogposts = array_diff($posttotid, $posttotid_press);
$blogposts = array_values($blogposts);
$posttotal = count($blogposts);
//i<=2 means displays last 2 posts
//display latest 2 posts...
for ( $i=1; $i<=2; $i++ )
{
?>
<div class="blog">
<h2><?php echo $col_posts->getItemById($blogposts[$posttotal-$i])->getPostDate(); ?></h2>
<h1><?php echo $col_posts->getItemById($blogposts[$posttotal-$i])->getPostTitle(); ?></h1>
<div style="float:left; margin-top:15px; margin-bottom:25px;">
<?php
$featured_img = $this->getSkinUrl('images/pree_emty.png');
if($featuredImage = $col_posts->getItemById($blogposts[$posttotal-$i])->getFeaturedImage())
{
$featured_img = $featuredImage->getAvailableImage();
}
?>
<img style="float: left;" src="<?php echo $featured_img; ?>" width="204" height="204" alt="" />
<div style="float: left; width: 580px; padding: 10px;">
<p><?php echo substr(strip_tags($col_posts->getItemById($blogposts[$posttotal-$i])->getPostContent()), 0, 400); ?></p>
<p>
<a href="<?php echo $col_posts->getItemById($blogposts[$posttotal-$i])->getUrl(); ?>">
<img src="<?php echo $this->getSkinUrl('images/view_btn.jpg'); ?>" width="170" height="32" alt="" />
</a>
</p>
</div>
</div>
</div>
<?php
}
?>