Wordpress Advanced Custom Field - Field Not Displaying - wordpress

I am building an artist directory page which displays all the artist pages as thumbnails with captions.
I would then like it so that when you click on one of the thumbnails it takes you to that page and shows the various fields ACF.
However, it only shows the title and I cannot get it to display the bio field at all!
<h1><?php echo $post->post_title; ?></h1>
<div id="artist-bio">
<?php the_field('artist_bio'); ?>
</div>

first, it's a good practice to check if your fields have been set in the first place. You can test like this:
if (get_field('artist_bio') {
the_field('artist_bio');
} else {
echo "Artist bio has not been set";
}
If it's claiming that it hasn't been set, yet you're sure it is, then there's probably an issue with the loop. Are you inside the default loop, or are you running a custom query? In the latter case you would need to modify your command like so: the_field('artist_bio', $post->ID).

Related

Wordpress admin: set category from variable instead of checkbox

The only way to set a category to a new post seems to be to select the appropriate one via a check-box before submitting it.
At best, you can set a default category as an option in case no box has been checked by the user.
This is really a problem for me as my admin menus are and have to be the categories themselves.
As I mentioned, in my WordPress admin I have a custom menu listing category names. Clicking on one leads directly to the generic "add a new post" page.
What makes it less generic is that I have inserted the category ID within this link, like this: "wp-admin/post-new.php?cat=5".
At this point,I would like not to check a category from a box before submitting the new post. Instead, I want WordPress to use the variable provided in the URL and submit the category ID accordingly when my new post is ready to be published.
Is it possible?
Which file would I have to edit in order to achieve this?
Any other idea that would lead to the same result?
You can use an extension that you will develop. It is better than trying to modify Wordpress core files.
I did something that may help you in one of mine. Using this :
if(is_admin()){
add_action('post_submitbox_misc_actions', 'plugin_add_custom_box');
}
function plugin_add_custom_box(){
?>
<div class="al2fb_post_submit">
<div class="misc-pub-section">
<?php
echo '<input type="checkbox" id="plugin" name="plugin_action" value="1"/>';
echo '<label for="plugin">';
_e("Label", 'myplugin_textdomain');
echo '</label> ';
?>
</div>
</div>
<?php
}
This add a custom checkbox. Using the same name for the checkbox here than checkboxes already displayed by Wordpress and checking it analysing your URL, you will probably be able to store the category you want without modifying core files.

Add Link Field in Template in Drupal 6 with CCK

Good Evening,
I'm using Drupal 6, CCK Module, and the Link Field Type. All are installed and activated.
I created a custom content type called Slider. A user can upload an image, a title, and a teaser. I created a custom field for that slider content type as well as one called Link with the field name: "field_link_test".
I created an entry, filled in all of the data including a URL for that link field type and clicked "Save". In views-view-table--slider.tpl.php, I added:
Learn More
but on the front end, everything shows except for that link. I also tried emptying the Drupal cache.
Any ideas?
Update template code below, which all works fine, except for the new link value outputs nothing.
<div id="slider">
<div class="slider-holder">
<?php foreach($rows as $row): ?>
<div class="slide">
<?php print $row['field_image_fid'] ?>
<div class="info-slide">
<h2><?php print $row['title'] ?></h2>
<p><?php print strip_tags($row['teaser']) ?></p>
Learn More
</div><!--INFO-SLIDE-->
</div><!--SLIDE-->
<?php endforeach ?>
</div><!--SLIDER-HOLDER-->
<div id="control">
</div>
</div><!--SLIDER-->
The easy possibilities (which you've probably checked, but just to get them out of the way):
you need to allow the field to be viewable by anonymous/authenticated users in User Management - Permissions
Otherwise, it's hard to tell without some code to analyse. Could you post your entire views-view-table--slide.tpl.php and if possible, your exported view or a link to the exported view?
EDIT
Now that I've had a chance to look at your view, I've made a couple of changes that should help.
The reason your link URL isn't showing is that you're including the "Node: Link" field in your View instead of the "Content: Link (field_link_test)" field. The first one will just link back to the original node rather than your custom link. Also, I don't think you can call the $node variable from views-view-table (at least, I don't get anything when I print it. Instead, you can use the $row variable.
I have a version of your template that prints out the URL in the field "link_test" with the label "Learn More." I put the "Learn More" text in the View itself as that'll be easier to edit and works better with the Link CCK type (which by default will want to add a title you add in the node edit screen).
The view export is here: http://pastebin.me/0ed2942f6953cb00cab1bd5386058a13. You can import this back into your site, but you may want to clone your original View first to make a backup, so that if this isn't what you want, you can use your old version.
The updated tpl is:
<div id="slider">
<div class="slider-holder">
<?php foreach($rows as $row): ?>
<div class="slide">
<?php print $row['field_image_fid'] ?>
<div class="info-slide">
<h2><?php print $row['title'] ?></h2>
<p><?php print strip_tags($row['teaser']) ?></p>
<?php print $row['field_link_test_url'] ?>
<?php //print_r($row); ?>
</div><!--INFO-SLIDE-->
</div><!--SLIDE-->
<?php endforeach ?>
</div><!--SLIDER-HOLDER-->
<div id="control">
</div>
</div><!--SLIDER-->
Let me know if you have any issues/questions.
Are you sure the template is getting picked up (add <p>heavymark</p> above the href... does it show up?)?
If above shows up, add a var_dump($node) above the anchor tag and post the output so we can get a better idea of what's there (you probably want to enable XDebug so you get better formatted output, if its not on already).
Make sure you add the link field to the view in the fields section. This should allow it to be themeable from within your template file. If you are still not seeing it, try using
print_r($rows,1);
or some variable of print_r to view all the rows that are available to be themed.

Trying to understand custom fields in WordPress

I'm trying to make my single.php page show more details about each project/item in a portfolio, with multiple larger image files that will display with captions to the right of the project description.
I'm thinking the best way to approach this would be to use the 'featured image' for the thumbnail display on the homepage which seems to be working now, but I've been trying to figure out Custom Fields to use for my other images (image1, image2, image3). I can't figure it out.
I go to "Enter new" under Custom Fields from the admin screen, enter image1 for the name. What goes in the Value field? How do I get it to work? I know I need to add some code to my single.php page... but what? And when/where do I upload the images themselves?
Any help would be greatly appreciated! I'm a little dense in the PHP department...
Have look at your single.php file. You will find the following lines, one near the top, the other lower down.
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
...
...
<?php endwhile; // end of the loop. ?>
Anything between these two lines will be applied over and over, once per blog post that happens to be displayed by that template file. So you should put your magic between those lines.
What you put there will be a mix of HTML and PHP. For instance, you might use this line:
<img src="<?php echo get_post_meta($post->ID, 'image1', true) ?>"/>
which combines
<img src=""/>
with
<?php echo get_post_meta($post->ID, 'image1', true) ?>
The PHP line looks up whatever value you have entered for the custom field named 'image1'. If you look at the HTML I used, you will see that this value is being placed inside the 'src' attribute. In other words, the value associated with 'image1' should be the url of that image.
You can expand upon this basic idea, but that's where your own creativity will have to come in.
[Is this not a repeated question?]

adding single.php page to wordpress or if condition for main page or post detail page

I use Barecity Theme for WordPress. i built everything, but now i need to add a single.php file to theme. now it displays all post content at homepage, I created a short_desc Custom Field. and I call it from code with;
<?php //get_post_meta($post->ID, 'short_desc', true); ?>
it is fine. but i need to display this short desc at home page listing, and the main content at details page. how can do that?
I appreciate helps!!
It sounds like what you are trying to do is show a custom field that you have set on a post on the index page (which lists all the posts).
To do that you'll need to modify index.php by adding your snippet where you would like to have the short description.
<?php echo get_post_meta($post->ID, 'short_desc', true); ?>
You need to use echo to display the results from the get_post_meta function.
Depending on how your posts are setup you can also use the More button when you write your posts. This will cut off your post at a certain point that you decide and only show that short part on the index and archive pages.
Another option would be to use
<?php the_excerpt(); ?>
Which shows the first 55 words (this can be adjusted though) of the post.
Hope that helps,
Paul

Associating an image with a post in WordPress

What's the best way to associate an image with a post in WordPress?
What I mean by that is when each post has a 'header' image which is not in the body of the post. You'd most likely use it to show a small image next to each post when they're listed somewhere.
I know you can use custom fields with posts, but are there any better ways of doing it?
Thanks in advance.
If you go the custom field route - in your template code you can save the value of the custom field to a variable and then echo it out to your image.
<?php $post_image = get_post_meta($post->ID, post_image, true); ?>
<?php if( $post_image != "" && isset($post_image) ) : ?>
<p><img src="<?php echo $post_image; ?>" alt="<?php echo $post_image; ?>" /></p>
<?php endif; ?>
<?php the_content('read more...'); ?>
The function the_content() may or may not be what you will end up using - for more control, you can try setting a new WP_Query() and then revamping the loop.
Not really any better way than custom fields, although you could always write out a unique class name containing the post ID on the container div and add the images via CSS each time you add a post. You'd end with a potentially huge CSS file though so I'd go for custom fields myself.
If you want a different image per post then use Customs Fields as suggested before - the only problem with that will be that Custom Fields are text fields and so you will have to upload your image and then paste the filename into your Custom Field. You could use the normal Add Image facility in the main post entry form but that will break up your workflow a bit as you will have to: upload the image in main post form, copy image url from HTML of form, remove image from form, paste URL into a custom field.
A bit of a pain!
If you want to use an image per category. Say, for example, you have a thumbnail for news items and a thumbnail for tutorials and so on. You could edit your WP theme template, check the category inside The Loop and show the relevant image from there.
The first option is a bit of a pain and the second requires some PHP coding.
A good way of associating an image with a post is to call the first image attached to that post in your template file.
I've elaborated a bit in this thread:
How would you recommend adding an image as a custom field in WordPress?

Resources