I have try to get answer from Wordpress Answer but instead of getting answer I earn Thmbleweed badge. :( anyways so I am trying here and hopping solution.
My new website going to have multiple author. All I need to do with that some specific system where Admin can add banner to the specific author's post.
Fore example xxx banner will only display on xyz author's post and not on any other author post. Which will have auto expiry system, it will automatically invisible when it reach to defined date by admin. All these systems will be under admin control only.
I am not php guy but can play with wordpress codes a bit. So I need really great help to work this out. I also won't mind to give full credit on my website credit display for this system.
Create a table with fields:id, authorid, banner_content, expiry_date.
To fill in the table with specific details of authorid,
banner_content, expiry_date create a simple form or directly enter in
the database.
After your table is created and is filled with details
HERE IS THE COMPLETE CODE TO DISPLAY THE BANNER
<?php
$getid = $posts[0]->post_author; //No need to change this
$sql= "SELECT * FROM bannertable wbanner WHERE author_id = $getid AND expiry_date>CURDATE();"; //change the table name 'bannertable' and field names 'author_id' and 'expiry_date' to your own
$banner_con=$wpdb->get_results($sql);
echo "<div class='banner'>";
foreach ( $banner_con as $content )
{
echo $content->banner; //change field name 'banner'.
}
echo "</div>
?>
Make sure to enter the above code inside the loop of your theme.
Related
I am using admin columns together with ACF (advanced custom fields)
in the backend I created a field in ACF for just some text, now with admin columns I made this field viewable in the backend for me to add some text that I want .
Now I want to display this text in the my-account page on the frontend.
now I got this far that i added the snippet code to the account page and that works .
But it's only displaying the DEFAULT value I have filled in in ACF and not the value I have entered in the admin custom column backend.
so to clarify even more in my users backend page i give the user a string of text.
That text needs to be displayed in the frontend on the users account
So all users should have a different string of text. The text I can add using admin columns
thats no problem but its only displaying (echo,printing) this text that I have filled in there to the woocommerce account page is not working.
Again I only get the default result text from ACF there not the text I had put in.
For getting default message the code that I use now is:
<?php echo the_field('ethwallet'); ?>
This is giving me the default message right now. not the result that I entered in the backend.
I realize this is an older question, but I wanted to provide an answer as it has been viewed several hundred times.
To retrieve custom meta data (specifically ACF field data) from a User object you need to pass in the current user ID as a second parameter to the get_field or the_field function.
Like so:
<?php echo get_field( 'ethwallet', 'user_' . get_current_user_id() ); ?>
The way it works is that ACF needs the second parameter formatted as user_X, where X is the actual ID of the user (1, 347, whatever). So we concatenate the string part ('user_') with the actual ID of the logged in user and that forms the full parameter to pass to the_field() or get_field().
P.S. It's a minor detail, but in this case echo the_field(); is redundant because the_field() echoes its values by default. You could likely omit the echo or do echo get_field();
I can't find a way to create a front-end profile page for all users under Wordpress Multisite Network. I also wanted the profile page to be on the main site and not on sub-sites if possible. I don't want to use any social network plugins like buddypress.. I just want to create a page like http://mainsite.com/profile/username
Is there a way to accomplish this?
Maybe you might check out Buddypress which is a social layer on top of Wordpress and is able to do what you need (i.e. something like http://mainsite.com/profile/username).
Link: http://buddypress.org/
More specifically, in Buddypress the default behaviour is http://mainsite.com/members/username
I have noticed that you have edited the question and that you are looking for a way to accomplish this without any plugin. There are a series of tags in Wordpress to show the author's data. So basically you could create a page and then use the_author_meta tags. For example the following code echoes the first and last name of a user whose name is stored in $userID:
<?php
$pagename = $userID;
echo the_author_meta(user_firstname, $userID );
echo the_author_meta(user_lastname, $userID );
?>
Please note that the variable $pagename is empty in case you use a static page as home page, but it is not your case.
Source: https://codex.wordpress.org/Template_Tags/the_author_meta
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.
I'm setting up a WordPress installation where I want some of the articles to show the date they were posted, and other articles to leave the date out. I'd like these articles to be completely dateless, if possible, so they only show in category archives and not in date archives.
I'm guessing I can tweak the templates to show the date or not based on the article's category, I was wondering if there was an easier solution to this?
Or should I start writing my own plugin to do this?
I've not got anything online at the moment, this is just an idea I'm churning over in my head for now.
Cheers,
Dan
Your theory of how to do it (have the theme files make a check for the category, then either display the date or not) is correct.
I think this code should do it:
<?php
if (is_category('CategoryThatDisplaysDates')) {
echo '<p>Date posted: '; the_date(); echo '</p>';
};
?>
If you don't want to mess up your categories (having “CategoryThatDisplaysDates” in a category listing looks a bit weird), you could try custom fields (meta-data). You add a custom field, e.g. display-date, in the write post panel and set its content to true.
Then, use ahockley's code, just change if(is_category(...)) to
if(get_post_meta($post->ID, 'display-date', true) == 'true')
i'd go with a custom field. you can read about using custom fields here: http://codex.wordpress.org/Using_Custom_Fields
I need to add an image to each page in WordPress.
I don't wish to insert it using the WYSIWYG editor, I just need the url as a custom field, which I later use in the template.
I tried using the CFI plugin (Custom Field Images), and I hacked my way into getting it to work with the rest of my plugins, but then I moved the site to the production server and CFI just didn't work for some reason.
I can't seem to find any other plugin that just lets you pick an image from the library and add it as a custom field.
I've downgraded to the point where I'm willing to manually enter all the URLs into each and every page. but before I do, I thought I'd check here.
Can anyone tell me what's the easiest, best way to add images as custom fields in WordPress (2.7.1 if it matters)?
In our WordPress template, each post generally only has one image 'attached', which is displayed outside the posts' (textual) content.
I simply upload the file using the edit posts' media uploader, never insert it into the post like JoshJordan above, then retrieve the image using a bit of code in the right place in my template file.
This would also work if you're using more than one image in your post, eg. in your post content. As long as you keep the image used as the 'main' post image as the first image (remember you can re-order images in your posts' image library by dragging them up and down), you're easily able to call it anywhere in your template file by using something like this:
<?php
$img_size = 'thumbnail'; // use thumbnail, medium, large, original
$img_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts where post_parent= $post->ID and (post_mime_type = 'image/jpeg' OR post_mime_type = 'image/gif') and post_type = 'attachment'");
$img_array = wp_get_attachment_image_src($img_id,$img_size,false);
echo '<img src="'.$img_array[0].'"' title="'.get_the_title().'" />';
?>
No need for copying and pasting image urls.
The template I have uses a manually-entered custom field for the splash image of each post. When I'm done writing my article, I upload an image, copy its URL from the upload tool, never insert it into my post, and then paste that URL into the "Image" custom field. Simple as pie and takes only seconds. Insignificant compared to the amount of time it takes me to write an article.
You can use the custom key value fields on posts as well. let's say you always give your images the key 'thumb'. you can then use this code to output them in your post as a thumbnail:
<?php
$values = get_post_custom_values("thumb");
echo “<img src=\”$values[0]\” class=\”thumb\”></a>”; ?>
Consider using Flutter it's a bit tricky to figure out at first, and has many really useful featured, including EIP (edit in place), and image handling.
After installing the plugin create a new "Write Panel", you'll figure it out from there. The plugin provides you with a rather intuitive GUI, which includes an image uploader. The template tags are very easy to use, I believe it's something like
<?php echo get_image('name_of_field'); ?>
I just had to build a site for a client that needed the same feature, I ended up using Flutter.