I want to show adsense ads only on those posts and pages which are written in the year 2011 using variables outside the "loop". It there any way of doing it in wordpress ?
This can be accomplished by using variables in the Wordpress loop. The "loop" is commonly used for pulling data like this. This answer is only applicable if you plan to put the ad within the Wordpress loop.
This snippet of code can help you get started:
if(the_time('Y')=='2011') {
echo adsense_custom_function();
}
See more here: http://codex.wordpress.org/The_Loop_in_Action#Title.2C_Date_and_Author
Related
For my WordPress site, I am using both PODS, and WPDataTables to manage my data. With that, I am using WPDT's "placeholder" feature to create dynamic SQL queries that will display different data depending on what user is logged in. Currently, I can ALMOST do everything I need, but not quite. This is more or less what I would like to achieve (var1 = the output of another shortcode):
[wpdatatable id=14 var1=
[pods name="User" template="Company" where="id = {#user.id}"][/pod]]
[/wpdatatable]
This shortcode is working, and will pull back a single number, based on the user that is logged in:
Company: [pods name="User" template="Company" where="id = {#user.id}"]
And this code is working if I hardcode a specific value to var1:
[wpdatatable id=14 var1=5]
Basically, I have two separate shortcodes that work individually, but will not work when put together. I was wondering if something like this would be possible? Or if I needed to maybe think of a new approach. Thanks in advance!
Side Note: I have tried using the "Outerbridge Nested Shortcodes" plug-in without any luck. After talking with the plug-in author, I discovered that this plugin only works for:
[tag-a] [tag-b] [/tag-a]
And not:
[tag-a [tag-b] ]
That's something wpdatatable needs to enable like we do it for pods but that would be around the other way see how it's done for pods: https://pods.io/docs/build/using-shortcodes-pods-templates/
I have recently written a blog post using blogdown through RStudio, and I am trying to use internal hyperlinks within the post. Specifically, I am trying to link a 'string of text' to another 'string of text' in a different section of the script.
For instance, I created a blog post that defines some functions in the first section of the document, and my goal was to link those function names to the section of the document where I give examples on using that specific function.
To clarify, it works great when I knit my Rmd; however, it stops working once the blog is posted. Although the function names still appear to be hyperlinked, you are actually brought to the home page of my website, and not the example section of the post which is what I want. If anyone could provide any suggestions or resources I would really appreciate it! Thank you!!
Please find the blog post here (with the internal hyperlinks not working) http://sarahrsalter.com/blog/2018-02-18-dplyr/.
Here is the Rmd code:
+ [**select()**](#Select): evaluates a subset of specified variables
(columns) within a dataset.
## II) Select Functions <a id="Select"></a>
### Example 1
I am working in an e-commerce site built with WordPress. I want to assign a zip code to each city in the country as users tend to misspell the names.
So I want it in a way that each time the type a city it's zip code appears.
Example when i type in New York I should have 00012 pop up.
Any suggestion would be welcomed.
Thanks
I have used one plugin please follow this plugin this will help to get zip code you need to do bit custom design if you need
here is link https://wordpress.org/plugins/simple-locator/
Their parent demo is here: https://locatewp.com/
I tried the following functions in header.php, footer.php, single.php etc.
var_dump(in_the_loop());
var_dump(get_the_id());
The first function gives false (meaning we are not in the loop) and the second function gives the post id every single time.
Description of get_the_id() from wordpress :
Retrieve the numeric ID of the current post. This tag must be within The Loop.
I just want a simple explanation what the hell is going on why do i get the post id if I call the function out of the loop !?
must is a little strong for get_the_id() ...delivers evil eye to Wordpress.
It works in the header and non-loop (confirmed).
Please note that post/page are essentially interchangeable in this conversation.
Think of WP this way -> You always have a post id in some way, all the time, every page, unless you do weird stuff or talk about non-page edge cases. When you are at the install root (such as site.com/) there are posts being called, something has to be displayed. There are other settings that will impact post/page such as static front page settings. On a category listing, if there are pages, I got the first ID returned before the loop.
On post/pages the page ID is (more or less0 set before the loop. This is a result of the URL (pretty or ?p=123 format) dictating the content. Using pretty names, the page at site.com/foo-bar/ will try to look up if there is content available via the permalink rules for "foo-bar". If there is content, the post ID is obtained. (simplified)
Later in the page build you get into the loop. However, before the loop you are also offered opportunities to change, sort, or augment the loop - such as changing the page IDs to be looped or sorting.
Regarding in_the_loop(), WP says
"True if caller is within loop, false if loop hasn't started or has ended." via http://codex.wordpress.org/Function_Reference/in_the_loop
in_the_loop() evaluates if the loop is in action (loop being key to the WP world). Also important - when you are in the loop WP can iterate over multiple page/post (IDs).
I don't have a 100% bulletproof explanation as to how the ID always shows, but when you dig into the API and various methods for hooking this might be a result.
I understand your confusion and agree with you. I think WP intended get_the_id() as a loop based tool, outside the loop you will get unpredictable results.
Hope that helps, I do enjoy working in WP, and I hope you do to.
I just think about that, easy to do in non cms site, but in wordpress site... i like to know YOUR approach to that problem
I have a BIG site (200 pages)... and at a lot of place, the info#something.com, the 000-000-0000 telephone and send your check to 123 easy street, Canada...
all that email, telephone, and address... should reside in one place (a post or a var) and when you need to insert it you should used the short code [tel] or [email].... but how...
is there a plusgin that can define var, or a tutorial to do that... do you only have to change it ONE for the whole site..
Any idea is welcome.... now, find and remplace is my friend !...
thanks in advance
You could try the Custom Config plugin:
http://wordpress.org/extend/plugins/custom-configs/
It will allow you to create custom global variables that are contained within the CMS (otherwise you'd be declaring these variables within the template config).
Usage to output a variable onto the page would be something like:
<?=get_config('myVariable','default')?>