I'm trying to output the inout from a subfield of a group in AFC.
With a regular textfield I just use:
<?php $ups4 = get_field('ups_four', 'option'); ?>
</a <?php echo $ups4; ?></a>
Which is simple enough, but I fail to do this with a subfield. I've tried to go through examples but nothing works.
The type group name is header_usps and the subfield name usp_1.
How do I echo the subfield in an element?
You can simply try it like this (Not sure what exactly you were trying to achieve with the <a> tag, but it was broken, so I fixed that as well):
<?php $ups4 = get_field('header_usps_usp_1', 'option'); ?>
<?php echo $ups4; ?>
Related
I'm stuck trying to echo my product descriptions correctly for my eCommerce store.
Is it possible to write formatted HTML (i.e. with elements and tags... to youtube links, etc) as text in a MySQL description field and then echo it with PHP correctly formatted?
At the moment I am using...
<?php
echo "<p>".Helper::encodeHTML($product['description'])."</p>";
?>
...but as I say it doesn't output as formatted.
Thanks for the help! :)
Edit; Fixed for the moment ('less anything changes) with...
echo html_entity_decode($var['string']);
i.e.
echo html_entity_decode($product['description2']);
http://uk1.php.net/manual/en/function.html-entity-decode.php
How about removing the p tag and echo it as is?
<?php
echo Helper::encodeHTML($product['description']);
?>
or echo it with htmlentities() like this:
<?php
echo htmlentities($product['description']);
?>
or echo it directly like this:
<?php
echo $product['description'];
?>
this is the piece of code I'm not sure how to deal with:
<?php echo get_post_meta($post->ID, 'smartslider2', true); ?>
<?php echo do_shortcode('[smartslider2 slider="InsertHere"]'); ?>
I simply want to insert the first echo instead of InsertHere. The first echo should output the content of a custom field. The second should recall the slider with the specific number inserted in the custom field. When trying different possibilities I only get errors.
Can anybody help?
Thank you :)
Don't echo the first value, use it directly inside your second echo.
<?php
echo do_shortcode('[smartslider2 slider="'.get_post_meta($post->ID, 'smartslider2', true).'"]');
?>
Or you can easily put that first value in a variable and use that variable in the second line
<?php $slider = get_post_meta($post->ID, 'smartslider2', true); ?>
<?php echo do_shortcode('[smartslider2 slider="'.$slider.'"]'); ?>
How do I echo a Wordpress plug in short code that I will be putting in the Custom Meta field in the post I have called Treatment 1?
Short code is
[table id=6 /]
My php which I cant work is
<?php
$post_meta = get_post_meta($post->ID, "Treatment Right 1", true);
if (!empty($post_meta)) {
?>
<?php echo do_shortcode($post_meta;); ?>
<?php
}
?>
Please help
<?php echo do_shortcode($post_meta); ?>
You have a semi colon inside your shortcode function for a start.
not 100% sure what you are trying to achieve.
Does the custom meta field just contain the name of the shortcode or the full string?
i.e. does it include the square brackets [shortcode] rather than just returning 'shortcode'
you could try:
echo do_shortcode('['.$post_meta.']');
have you written the shortcode function of 'table' yourself?
I am using wordpress get post meta to store the value of a custom field into a variable. In this particular instance, It is actually grabbing the post's parent's custom field due to the $post->post_parent Here is the code:
<?php $cast_members = get_post_meta($post->post_parent, 'cast_members', true); ?>
<p><?php echo $cast_members; ?></p>
<?php endif; ?>
The custom field cast_members is a series of cast members, each in its own paragraph. For some reason wordpress is stripping out the paragraph tags and displaying all of the cast members in a continuous string. I need to retain those paragraph tags so each cast member is on its own line. Any idea why get_post_meta strips out tags and how to fix it?
Why not do something like this,
<?php
$mykey_values = get_post_custom_values('cast_members',$post->post_parent);
foreach ( $mykey_values as $key => $value ) {
echo "</p>". $value ."</p>";
}
?>
Or you ca use your original query but just add a foreach to echo out the value wrapped in <p> tags.
Thanks to #Vinod Dalvi the answer involves using wpautop like so:
<p><?php echo wpautop($cast_members); ?></p>
I'm using Views 3 in Drupal 7 to output a list of fields and using a grouping field to generate separate lists. I need each of the groupings to have a unique ID attribute applied to the < ul > but they don't by default.
As far as I'm aware I would need to edit the views-view-list.tpl.php template but I don't know how to achieve a unique ID per iteration.
Can anyone help please?
easiest way I can think of off the top of my head...
<?php print $wrapper_prefix; ?>
<?php if (!empty($title)) : ?>
<h3><?php print $title; ?></h3>
<?php endif; ?>
<ul id="<?php echo uniqid(); ?>">
<?php foreach ($rows as $id => $row): ?>
<li class="<?php print $classes_array[$id]; ?>"><?php print $row; ?></li>
<?php endforeach; ?>
</ul>
<?php print $wrapper_suffix; ?>
that would go in your views-view-list.tpl.php file.
For future reference:
Put a div around everyting in view-views-list.tpl.php. You can (ab-)use the $title to generate unique (but consistent) id's.
Do it like this:
<?php $id = str_replace('FOR ALL UNWANTED CHARS','',$title); ?>
<div id="<?php print strtolower($id); ?>">
You can use the $view->dom_id variable. It is a unique id for that views instance.
In your .tpl.php file:
<?php print $view->dom_id; ?>
From comments in modules\views\theme\theme.inc:
<?php
// It is true that the DIV wrapper has classes denoting the name of the view
// and its display ID, but this is not enough to unequivocally match a view
// with its HTML, because one view may appear several times on the page. So
// we set up a hash with the current time, $dom_id, to issue a "unique" identifier for
// each view. This identifier is written to both Drupal.settings and the DIV
// wrapper.
?>