How to target a single viewed post page on Wordpress? - wordpress

I want to add an HTML tag if the page viewed is a 'viewed post page'.
For example, if I have a blog and I am viewing the list of posts - after I click on the post and see the whole text and see all the post - I want to echo an HTML text.
I tried using if ( !is_single ){}...
I tried using if ( !is_single($post) ){}..
I tried using if ( !is_singular ){}
The only thing I find on Google is how to target specific posts.
I went through the conditional tags too: https://codex.wordpress.org/Conditional_Tags
I didn't find what I'm looking for.

Related

Which conditional tag is correct to have a different style on a page

I need to add an ads in a Wordpress page but I'm not able to localize it.
I have tried with the " is_archive " conditional tag but it shows me the ads in the page and not in the subcategory ( page ).
What is the correct conditional tag to use?The structure should be PAGE - CATEGORY - SUBCATEGORY. In the PAGE I put a shortcode ( custom menu wizard plugin ) which display a menù. This menù it's a list of subcategory.
If you want you can check the page ( where i put my name instead of the ads to make a test ) which is this one http://www.alesitiprova.it/acciaio-nodi/ ( I wrote CIAO ALESSANDRA DE ROBERTIS ).
But i would like to show this text by clicking on the link menu ( Altri, Pilastri e fondazioni, Pilastri e Travi )
If you click for example in "Altri" you open this page http://www.alesitiprova.it/category/particolari-costruttivi-dwg/acciao-nodi/altri-acciaio-nodi/
In this page i would like to see "CIAO ALESSANDRA DE ROBERTIS ".
Can Someone help me?
Since the pages you are trying to detect are category archive pages, you should probably use is_category('slug-of-category') instead of is_archive().
So for example, if you want to detect the category "Altri", you can use is_category('altri')

Hide a post but make it accessible via a link Wordpress

I'm trying to hide certain posts from displaying on the site using custom code. I CANNOT USE A PLUGIN!
I would like to do something like IF the page is named the-hidden-page do not display it anywhere on the site BUT someone can access it using a URL... For example, http://thedomain/the-hidden-page.
I haven't been successful finding sample code except for this -
<?php if (is_front_page() && !is_paged()
) $posts = query_posts($query_string . '&cat=-33,-66'); ?>
This code is using category names rather than page names. Also if I used the code above I'm not sure where to add it to. I tried function.php but that didn't work.
Can someone provide an example of how the code could be written to hide post with a certain name?
Also tell me in what file I should add your code to?

Adding A Button Between post-content and Related Posts Thumbnail Plugin on WordPress

I am trying to add a button to my WordPress template. Basically, I have the post and then there is the Related Posts Thumbnails widget that appears. I want the button to go between the text of the post and the related posts thumbnail widget. The code in my 'Single Post' that contains all of this is as follows:
<div class="post-content">
<?php the_content(__('<em><strong>More:</strong> Read the rest of this entry...</em>', 'life-is-simple')); ?>
</div>
I know the Related Posts Thumbnails plugin falls within this code because it's at that place when I 'Inspect Element' on Google Chrome. I can't find how to edit the order of things within that div though. Any help would be greatly appreciated, thanks!
EDIT
Clarification: I am using the Life Is Simple WordPress theme although it has been custom editing quite a bit (mostly on the CSS side of things though).
That plugin is probably appending the output to the_content with a filter .
That means , that the output is being added to the_content automatically. it is a common behaviour.
You need to look at the plugin´s admin interface to see if you can have an alternative way (I believe there is ) which is using a template tag. in that case, you should put the template tag after the div where the the_content() is .
EDIT I :
After a small dig, - in fact there is - you need to put
<?php get_related_posts_thumbnails(); ?>
Then the plugin should know by itself not to append to the_content.
For parameter passing, or if something is not working, go read their APi or help files.
You'll probably need to edit single.php or archive.php in your theme. If nothing is occuring there that looks familiar, it's probably using a loop. In which case you might find what you are looking for either in loop.php, loop-single.php, or loop-archive.php depending on what type of page you are on and how the theme was constructed. Add your button near where you find Read the rest of this entry...
With more information (such as what theme you are using), one might be able to help more as well.

Wordpress multiple / exclusive posting pages

I want a site with a separate News and Blog page, ie only news posts are dispayed on news pages and non news posts on blog pages. Also archive lists, category lists, etc for each page must only display relevant posts. Seems like a common requirement, but using the WP documentation, I keep going around in circles!!! Is there a simple way to do this, without getting into multiple blogs, eg using categories.
Thanks
That's easy.
First, you will need to create custom page template. Refer to this page to see how to create it.
Second, on that page (you can copy from your page.php/index.php, the important part is:
if (have_posts()) : while (have_posts()) : the_post();
Find that piece and add this code just right above that code:
query_posts('cat=3&paged='.get_query_var( 'paged' ));
Things to note from above query_posts snippet is:
cat: this is the category ID you want to query. To easily see what ID is on a particular category, you can use ShowID for Post/Page/Category/Tag/Comment plugin.
paged: Paged will allow your custom page to handle next & prev navigations, which is handled by next_post_link() and prev_post_link(). As for get_query_var( 'paged' ) is function to get what page's page you currently see.
Hope that helped.
<shamelessplug>
I blogged it here (in Bahasa Indonesia, which you can easily translate using google translate).
</shamelessplug>

WordPress - how to insert html code selectively in posts

I want to display custom html code when a post is rendered (so not when is inserted into the database).
I currently do this with add_filter('the_content', 'my_custom_method'). The only problem is that I want this do be displayed only inside the post (when is viewed in its own page), not when all posts are rendered .
I banged my head against the wall, but couldn't find any method to tell me if i'm currently inside an individual post or not (this has to work for every url rewriting possible, so i can't rely on url)
Is there such a method? I believe it should be, but i can't find it. Thanks.
the function for checking if the post is in its own page is is_single()
add_filter('the_content', 'my_custom_method');
function my_custom_method(){
if(is_single()){
//code for your custom html code
}
}
the function is_single() checks if the page being rendered is a single page or not.
The easiest way to do this would be to modify your templates. Wordpress template sets should have a file named single.php (inside wp-content/themes/<theme name>). This is the page that gets rendered when you are viewing the page for a single post.
You could edit this file and insert whatever you needed to for the posts there.

Resources