I'm using advanced custom fields to show complementary products on widget. I add title before complementary products. I want to hide that title when acf field is empty. How can I do it? field name is:tamamlayici_urun_1_gorseli
You can use the below code I hope it will work. When this field empty then
Example:
<?php if( get_field('tamamlayici_urun_1_gorseli') ): ?>
<p> Title Show </p>
<p>Field Value: <?php the_field('tamamlayici_urun_1_gorseli'); ?></p>
<?php endif; ?>
Related
I am using <?php the_category(); ?> to display the categories of my post.
It was displaying but my problem is the permalink it produce.
the category link give this for example: http://samplesite.com/category/funpage/
what I want is to remove the category in the link and just produce: http://samplesite.com/funpage/
also, I am using custom post type UI to create post.
anyone can help me please?
You can use get_the_category() function and get all categories for that post and display using loop.
<?php
foreach((get_the_category()) as $category) {
?>
<a href='url you want to pass add here '><?php echo $category->name; ?></a>
<?php
}
?>
Disclaimer: If you have never used ACF Flexible Content to build a site, please reserve the hate and all that - looking just for help.
I'm creating a website that's 100% modular, done with Flexible Content.
I have Pages such as:
Home, About, Services, Blog, Portfolio, Contact
All of those pages styled using Flexible Content, these are PAGES.
I have created a custom field for Services and Portfolio, and I used WP Query to display each individal item. These are CUSTOM fields. Show this field group if post type to Services. Not a page.
So when you click it, what happens you go to single-[custom-post-type].php, however I just have single.php to keep it dynamic, which works.
The problem lays that when I have showed the flexible content page templates in the Services or Portfolio, and I add few items, I need go to every single item and set the layout.
How can I do so the layout stays all the same in Service or Portfolio custom field?
Firstly create your ACF Master block, for example, a testimonial section, this would have the repeater fields inside the block etc. In this example, we will call it Testimonial Master.
Then Create another Flexible Content Field Called Testimonial Block with a checkbox that you check to display or hide.
You will now populate Testimonial Master on your selected Parent Page or on an Options page. You then should add the Testimonial Block to any page you are looking to have that block appear on.
You will then went to check that the Testimonial Block is on the page, if it is on the page then you will check if Testimonial Master has a value if it has a value then you can pull in the values from Testimonial Master.
<?php
if( have_rows('page_structure') ):
while ( have_rows('page_structure') ) :
the_row();
if( get_row_layout() == 'testimonial_block' ):
if( get_sub_field('testimonial_block_toggle') == 'show' ):?>
<div class="testimonials">
<?php the_sub_field('testimonial_master_title', 1); ?>
</div>
<?php endif;
endif;
endwhile;
endif;
?>
The "1" is the page ID, use this if you have populated the field on a master page. Or if you are using the ACF Options Page plugin change the "1" to "'options'".
Here is some further documentation on getting values from other posts including that of repeater fields.
https://www.advancedcustomfields.com/resources/how-to-get-values-from-another-post/
Edit: Custom Header as per your example
Make a custom header file and add your code for that header block.
Now make an advanced custom field for a text area. For example header_text_block, set it to a WYSIWYG editor.
Now in your code just use:
<?php the_field('header_text_block');?>
This will then use the exact same header on every page you pull it into, however it will let you edit the text individually for each page.
Edit: Example of what this code looks like and does
Also I think you are very confused, there will only be 1 php/html file? you could use page.php.
Here's an example of what I am saying, 1 php file:
<?php if( have_rows('page_structure') ):
while ( have_rows('page_structure') ) : the_row();
if( get_row_layout() == 'page_featured' ):
$image = get_sub_field('page_featured_image');
if( !empty($image) ):?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>">
<?php endif;
endif;
if( get_row_layout() == 'page_breadcrumbs' ):
if( !in_array( 'hide', get_sub_field('page_breadcrumbs_hide') ) ):?>
<?php if ( function_exists('yoast_breadcrumb') ) {yoast_breadcrumb('<p id="breadcrumbs">','</p>');}?>
<?php else :
endif;
endif;
endwhile;
endif;
?>
This then looks like this on the page editor:
You can then edit each section as you please and also drag and drop sections where you want them which enables easy split testing.
All the styling will be the same, just you can change the content and if you wanted you could add the ability to alter stylings pretty easily. And it only uses 1 PHP file for the template.
Orignal Code
<h5 class="entry-title">'.get_the_title().'</h5>
I want to add this code that ACF image field to show and it replaced on title
<?php $shortlinestory = get_field( 'shortlinestory' ); ?>
<?php if ( $shortlinestory ) { ?>
<img src="<?php echo $shortlinestory['url']; ?>" alt="<?php echo $shortlinestory['alt']; ?>" />
<?php } ?>
My Custom image field name is shortlinestory in a widget i want to show the recent image please help me thanks
To get the custom field of a widget you have to add an additional parameter in the get_field() function. Advanced Custom Fields has pretty decent documentation and it is explained here how to do that.
First you have to figure out the ID of the widget. This is passed to the function that creates the widget for example $widget_id = $args['widget_id']. Then you can use the_field('field_name', 'widget_' . $widget_id) to get the custom field value.
Hope that helps you out, good luck!
I have created custom post type portfolio in wordpress. I have created categories like web-design, logo design, e-commerce, photography... etc. I have retrieved all these category as the navigation menu in portfolio template file (assigned to the portfolio page). Now I want there should be a link(view all) in the navigation menu which will retrieve all the posts from all the categories in portfolio. Basically I want a way for making default category which will retrieve all the posts. Can anybody please help me!!!
So, basically, you want to create a Custom Post Type Archive page.
A way to achieve this, as explained at WPBeginner.com, is like the following:
Create a custom page template (the PHP file could have any name you want) and Add the Template Name comment at the beginning of the file:
<?php /* Template Name: Custom Post Type Archive */ ?>
Create a custom loop:
<?php
/* Template Name: Custom Post Type Archive */
get_header();
?>
<?php
global $query_string;
query_posts($query_string . "post_type={YOUR-CUSTOM-POST-TYPE}&post_status=publish&posts_per_page=10");
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<?php
endwhile;
endif;
?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('Previous entries') ?></div>
<div class="alignright"><?php previous_posts_link('Next entries') ?></div>
</div>
<?php wp_reset_query(); ?>
<?php get_sidebar(); ?>
<?php get_footer();?>
Create a new page and select the template you just created in the Page Attributes box
You should be able to use the archive page template to list them all then. Try going to http://yourdomain.com/portfolio and see if that brings it up. You will need to have enabled archives for the post type when you created it though. Look for 'has_archive' => true, if you created the post type manually by dropping in the code in your functions.php file. If you see that, but its set to "false", you'll need to change it to true.
You could also create a custom archive template for this post type if you wanted to. If you create a new file in your theme directory called archive-portfolio.php and then put a custom loop in there the post type will automatically target that template file when accessing the post type archive.
Then to link from your nav menu to this archive, just create a custom menu item in your menu editor with the url http://yourdomain.com/portfolio. You won't need to create any sort of "default" category if you take advantage of the post type archives.
Let me know if you have any other questions.
In Drupal 6, I added a custom field to a custom content type.
The name is: "field_publishedin"
I then added data into that field for some sample articles.
In the view for it, I added that field as well.
On the page that renders it I added the code to show the field as well:
<div class="press-content">
<div class="family-news">
<?php foreach($rows as $row): ?>
<div class="news">
<div class="data">Posted on <?php print $row['created'] ?> </div><!--DATA-->
<h4><?php print $row['title'] ?><span><?php print $row['field_publishedin_value']; ?></span></h4>
</div><!--NEWS-->
<?php endforeach ?>
</div>
</div>
So the code I added is <span><?php print $row['field_publishedin_value']; ?></span> since according to the view when using in a template you are suppose to add "_value".
However, I clicked rescan templates, emptied the drupal cache but that new code still does not render on the page.
When I add this to the page: <?php print '<pre>' . htmlentities(print_r($rows, 1)) . '</pre>'; ?> and it outputs the possible array values it does not show, "field_publishedin_value" so it seems like the template doesnt know that field exists even though its in the view. Help?
install the devel module, and in to *.tpl.php, place:
<?php
dpm($fields); // if views
// or dpm($node); if it's a node or page.tpl.php
// of if you don't know, dpm(get_defined_vars());
?>
Also, if this is views, the template you should be using is the views-view-fields.tpl.php. Note the PLURAL fields.
Joe