I am working on a social media network, and in my posts, I am trying to add the glyphicons found in Bootstrap 3 to the posts. Now, I have managed to the the icons on the same line as the username, but I can't work out how to get the username first, and then the glyphicons. Below is my code:
<div class="media well single-post" id="post-<?php echo $post['post_id'];?>">
<div class="avatar large pull-left">
<?php if ($this->profile_type === 'page' || $post['post_wall_profile_type'] === 'page'):?>
<a href="<?php echo $this->baseUrl()?>/<?php echo $post['post_wall_name'];?>">
<img src="<?php echo $this->GetStorageUrl('avatar') . $post['post_wall_avatar'];?>">
</a>
<?php elseif ($this->profile_type === 'feed' && $post['post_wall_profile_type'] === 'group'):?>
<a href="<?php echo $this->baseUrl()?>/<?php echo $post['post_wall_name'];?>">
<img src="<?php echo $this->GetStorageUrl('avatar') . $post['post_wall_avatar'];?>">
</a>
<?php else:?>
<div class="pull-right"><?php if (isset($post['author_meta']['badges'])):?>
<div class="network-badges vertical">
<?php echo $this->partial('/partial/badges.phtml', array('badges' => $post['author_meta']['badges']));?>
</div>
<?php endif;?><div class="pull-left"><a href="<?php echo $this->baseUrl()?>/<?php echo $post['user_name'];?>"></div></div>
<div class="pull-left"><img src="<?php echo $this->GetStorageUrl('avatar') . $post['user_avatar'];?>">
</a></div>
<?php endif;?>
</div>
Here is what it currently looks like: http://www.startrekrisa.com/Picture1.png
I know it's gonna be a simple fix, but I cannot work out how to do it.
Thanks in advance
[Edit] See this jsfiddle based on the fixed markup below and the /partial/badges.phtml code you gave in a comment; obviously your global css is not there, but you can see it properly puts the avatar left and the glyphicons to the right of it [/Edit]
The HTML you generate with that piece of code doesn't seem quite right, and considering your question only relates to html/css, it would have been better to strip your code sample down to a piece of html+css, without the php logic.
From what I can see, your question directlly concern the else part of your main logic, when the inner if is true. In that case I believe your code will generate
<div class="media well single-post" id="post-1234">
<div class="avatar large pull-left">
<div class="pull-right">
<div class="network-badges vertical">
<!-- content of /partial/badges.phtml with the user bages -->
</div>
<div class="pull-left"><a href="http://example.org/users/username"></div>
</div>
<div class="pull-left"><img src="http://example.org/avatars/username">
</a>
</div>
</div>
You can see here you have html problems:
your pull-left div is closed before the link inside is closed; the link inside is closed further on
you have a mismatch between open and close tags for your div
I believe the html you'd want would be more like
<div class="media well single-post" id="post-1234">
<div class="avatar large pull-left">
<div class="pull-right">
<div class="network-badges vertical">
<!-- content of /partial/badges.phtml with the user bages -->
</div>
</div>
<div class="pull-left">
<a href="http://example.org/users/username">
<img src="http://example.org/avatars/username">
</a>
</div>
</div>
</div>
Mixing php logic with your html like that is not terrific and will lead you to more similar problems where you end up not generating the markup you imagined.
P.S. It usually a good practice when working on the interface to first work without any logic behind and just static data, to ensure you get the markup you want and need, and then only merge this with your logic (but it's still better to have your logic separated from the ui though)
Related
I'm currently working on a materialize project and I have a problem with the grids.
Indeed, my php generate 4 columns l-4 and the 4th go to the right side as show here
<div class="row equipe">
<h2><?php echo 'Equipe n°'.$data2[1].' '.$nomjeu2[0]?></h2>
<?php
$stmt3->execute(array($data2[0]));
while($infoplayer = $stmt3->fetch()){
?>
<div class="col s12 m6 l4">
<div class="card-panel">
<img class="responsive-img" src="<?php echo $infoplayer[2]?>">
<p><?php echo $infoplayer[1]?></p>
<?php if($infoplayer[3] != ''){?>Twitch<?php } ?>
</div>
</div>
<?php } ?>
</div>
I don't really know what do to do here some help would be appreciated :D
Currently Materialize's grid is based on floats and it gets broken if cards are not of the same height. The card that is larger in the first row pushes the second row to the right. To avoid that it's easier to use custom styles with flex or grid.
So I have a WP_Query looping through my custom post types and I'm looking to customize the src of my image tags based on which post in the loop it is. What is the cleanest way to achieve this.
consider this as what my loop is spitting out on each iteration:
<div class="partnerships p-section">
<div class="-display-inlineBlock partnerships icon">
<img style="min-width:71px;" src="<?php bloginfo('template_url')?>/images/icons/trainingAndDevelopment.svg">
</div>
<div class="-display-inlineBlock" style="width:70%">
<h1><?php the_title();?></h1>
<hr>
<p><?php the_content(); ?>
</p>
</div>
</div>
Why you don't use post thumbnail?
<div class="partnerships p-section">
<div class="-display-inlineBlock partnerships icon">
<img style="min-width:71px;" src="<?php the_post_thumbnail_url(); ?>">
</div>
<div class="-display-inlineBlock" style="width:70%">
<h1><?php the_title();?></h1>
<hr>
<p><?php the_content(); ?>
</p>
</div>
</div>
EDIT:
Then you need to allow upload SVG.
But BE WARNING: Allow upload SVG is not good for security
(take a look: https://secupress.me/blog/add-svg-support-in-wordpress-medias-yes-but-no/)
So DO NOT USE THE FOLLOWING CODE, which one can see everywhere.
function custom_mtypes( $m ){
$m['svg'] = 'image/svg+xml';
$m['svgz'] = 'image/svg+xml';
return $m;
}
add_filter( 'upload_mimes', 'custom_mtypes' )
FIRST SOLUTION
I don't know how to clean SVG on upload, luckily a plugin that does all that exists. This plugin also fixes some others issues with svg.
https://wordpress.org/plugins/scalable-vector-graphics-svg/
SECOND SOLUTION
If only admin need to upload svg
You can use following code:
function custom_mtypes( $m ){
if(get_current_user_id()==1){
$m['svg'] = 'image/svg+xml';
$m['svgz'] = 'image/svg+xml';
return $m;
}
}
add_filter( 'upload_mimes', 'custom_mtypes' );
If you speak French here is an interesting discussion on this subject
https://wpchannel.com/autoriser-envoi-fichiers-svg-wordpress/ (read comments, DON'T USE THE CODE on the top of this article)
I'm having a little bit of a problem. My page.php seems to be overriding WooCommerce's cart page. The page is already created (generated by WooCommerce with the shortcode intact) named Cart.
I know that my page.php is overriding it, but I don't know how to stop that. Here is the code for my page.php page:
<?php
get_header();
if ( have_posts() ) {
//Work with us page
$workwithuspage = "work with us";
$pitch = "pitch an idea";
$cart = "cart";
if($workwithuspage == strtolower(get_the_title()))
{
//Page stuff here!
$image = wpse_get_images();
?>
</div>
<div class="hero">
<div class="container heroImage" style="background-image:url('<?php echo $image->guid;?>');">
<div class="col-md-7"></div>
<div class="col-md-5">
<div class="pageText">
Work with Us
</div>
<div class="subText">
<?php echo $image->post_content; ?>
</div>
</div>
</div>
</div>
<div class="bodyBg">
<div class="container">
<div class="col-md-6">
<div class="box-style">
<div class="box-header">
Got a comic idea and want it published?
</div>
<div class="box-text">
Tell us your desires, so we can slap it on a comic book and sell it for millions. Ya dig?
</div>
<div class="box-button-container">
<?php
$pitch = get_page_by_title('pitch an idea');
?>
<div class="button large">Pitch an Idea</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="box-style">
<div class="box-header">
Want to work on one of our great titles?
</div>
<div class="box-text">
Tell us your desires, so we can slap it on a comic book and sell it for millions. Ya dig?
</div>
<div class="box-button-container">
<div class="button large">Find Jobs</div>
</div>
</div>
</div>
</div>
</div>
<div id="ourstandards">
<div class="coloroverlay">
<div class="container">
<div class="col-md-6">
<div class="pageHeaderText">
Our Standards
</div>
<div class="bodyTxt">
<p>
At On Target Network, we strive to promote consistency,
communication and passion in all areas of work and we expect the same of our artists.
</p>
<p>
We understand the nature of creators and seek to raise ourselves to higher and higher standards. To do that, we vet and
review series pitches with a carefully selected panel of writers and artists.
</p>
<br /><br />
<p>
Got questions? We'll be happy to help.
</p>
<div id="sendUsQ" class="secondaryBtn">
Send us your questions
</div>
</div>
</div>
<div class="col-md-6"></div>
</div>
</div>
</div>
<div class="container">
<?php
}
else if($pitch == strtolower(get_the_title()))
{
?>
</div>
<div id="pitchImg" class="hero">
<div class="container">
<div class="col-md-7"></div>
<div class="col-md-5">
<div class="pageText">
Pitch an Idea
</div>
<div class="subText">
<?php echo $image->post_content; ?>
</div>
</div>
</div>
</div>
<div class="bodyBg">
<div class="container">
<div class="col-md-12">
<div class="pageHeaderText dark">
Start your pitch here
</div>
</div>
<div class="col-md-9">
<?php
if ( isset($si_contact_form) ) {
echo $si_contact_form->si_contact_form_short_code( array( 'form' => '1' ) );
}
?>
</div>
</div>
</div>
<?php
}
}
get_footer();
?>
I have conditional ifs for pages I wanted to customize, but I fear in doing that, it has overridden (somehow) the cart page.
WooCommerce adds the cart using shortcodes; shortcodes get displayed as part of the page content. WP uses the the_content() function to display the content for a particular page or post. You've removed the_content() from your page template, therefore the cart doesn't display.
Looking at your page template, you've removed the_content() and inlined all your content directly into the template rather than fetching it from the database. This is atypical of a WP site in general, but I understand that sometimes a site starts off static and you just want to get it 'into' WP.
You're also using a bunch conditionals to display different chunks of content, which runs against the idea of using templates. My suggestion would be to create separate page templates for your 'pitch' and 'work with us' pages, and make page.php just a default page template that has the_content(). This way you have a generic template you can use for any page, including the cart page.
Check the codex for more info on creating custom page templates, but in a nutshell, you add a comment to the top of the file:
<?php
/*
Template Name: My Custom Page
*/
Then save your file in your theme folder. Common practice is to name it along the line of page-pitch.php so you can easily identify it. Then in the admin area you can assign the template to any page you want simply by selecting it from the drop down menu.
Splitting your different content into separate templates has a couple of benefits; namely you no longer have to use conditionals for checking the page titles (which can vary from install to install) and makes it much easier for you to debug things.
Good Morning and Seasons Greetings! I am looking for help. I am trying to create a custom post, single page template where I want to embed a slider that fetches images, title and excerpt from the data of the same post. Let me describe the problem I seek help for.
The BACKGROUND Info
1) I have created a custom Post Type called "HPC Products"
2) It is linked with Custom Taxonomy called "HPC Product Categories"
3) The custom fields group for HPC Product includes Key Highlight 1, Key Highlight 2, Key Highlight 3 (all 3 as Single text fields) it also has fields called Product Image 1, Product Image 2, Product Image 3 (All 3 Image fields) , there are some other fields too such as title, features etc,
4) I have made a Custom Content Template for the Single-HPC-Product.
THE GOAL (Which I am not able to achieve)
Within the single-hpc-product page, I have the title and tagline followed by product description.Under that I want to have a slider with 3 slides.
Slide 1 – Should fetch Prod Image 1, The title of Key Highlight 1 and the Details of Highlight 1
Slide 2 – Should fetch Prod Image 2, The title of Key Highlight 2 and the details of Highlight 2
Slide 3 – Should fetch Prod Image 3, The title of Key Highlight 3 and the details of Highlight 3.
I have searched a lot of the forum strings, I have tried more than 25 different attempts at views and templates with different options such as Post is Parent, Post is Child, – Template is slider, template is custom display etc etc, But for some reason I am not getting success.
I really would be grateful if you could help me out by guiding me with simple steps to do this, I am a newbie with no knowledge or experience in php or coding.
I think you are using Advanced Custom Fields plugin to create your custom fields. If not use get_post_meta() instead of get_field()
First you need to find a slider that match with your requirements. After you found one look at it's markup. Imagin it's look like following code ,
<div id="slider-main">
<div class="slide">
<img src="images/img1.png" />
<span class="caption-1">Key Highlight</span>
<p class="caption-2">Key highlight details</p>
</div>
<div class="slide">
<img src="images/img2.png" />
<span class="caption-1">Key Highlight</span>
<p class="caption-2">Key highlight details</p>
</div>
<div class="slide">
<img src="images/img3.png" />
<span class="caption-1">Key Highlight</span>
<p class="caption-2">Key highlight details</p>
</div>
</div>
your template file look like this,
<?php get_header(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<div id="main">
<div id="slider-main">
<div class="slide">
<img src="<?php echo get_field('product_img1'); ?>" />
<span class="caption-1"><?php echo get_field('key_highlight1'); ?></span>
<p class="caption-2"><?php echo get_field('highlight_details1'); ?></p>
</div>
<div class="slide">
<img src="<?php echo get_field('product_img2'); ?>" />
<span class="caption-1"><?php echo get_field('key_highlight2'); ?></span>
<p class="caption-2"><?php echo get_field('highlight_details2'); ?></p>
</div>
<div class="slide">
<img src="<?php echo get_field('product_img3'); ?>" />
<span class="caption-1"><?php echo get_field('key_highlight3'); ?></span>
<p class="caption-2"><?php echo get_field('highlight_details3'); ?></p>
</div>
</div>
</div>
<?php endwhile; ?>
<?php get_footer(); ?>
I use this code for navigation in my front page:
<h13><div class="navigation">
<div class="next-posts">
<div id="image_left"><?php next_posts_link('<img src="IMG URL"/>') ?></div>
<div id="posts_left"><h12><?php next_posts_link('Older Stuff') ?></h12></div>
</div>
<div class="prev-posts">
<div id="posts_right"><h12><?php previous_posts_link('Newer Stuff') ?></h12></div>
<div id="image_right"><?php previous_posts_link('<img src="IMG URL"/>') ?></div>
</div>
I want the same navigation for my single post view but I can't get it to work, I made the changes for PHP functions but in Codex I only found a vay to display posts from the same category.
Also, I don't want the link to display previous/next post's title, only text that I define.
One last thing, I can't get the image navigation to work at all in single view, but it does work flawlessly in my home page.
This is my code at the moment:
<h13><div class="navigation">
<div class="next-post">
<div id="img_left"><?php next_post_link('<img src="IMG URL"/>') ?></div>
<div id="post_left"><h12><?php next_post_link('%link', 'Next post', TRUE); ?></h12></div>
</div>
<div class="prev-post">
<div id="post_right"><h12><?php previous_post_link('%link', 'Previous post', TRUE); ?></h12></div>
<div id="img_right"><?php previous_post_link('<img src="IMG URL"/>') ?></div>
</div>
h13 and h12? I didn't know headers went up that high!
I'm guessing you already read the Codex Page for the next_post_link() function. But did you make sure to include the call in the loop? Also, try adding in the extra parameters to the functions. Sometimes they get confused.