Wordpress and Internal Page Links - php

I'm trying to construct a Table of Content on a custom template in Wordpress. Because I already know beforehand the headings of the internal sections I want to link to I hardcoded that into the template.
My problem is that in Wordpress it doesn't scroll to that section at all? Here's the link to a page with an existing TOC section that's not working.
In terms of code, this is an illustration of what I got:
<div class="table_content">
<h4>Table of Contents</h4>
<ol>
<li>Overview</li>
</ol>
</div>
Which should link to an internal section with the code:
<h2><a id="#test_link" class="internal"><?php the_title(); ?></a></h2>
Note: I'm using "ID" instead of "name" because it's deprecated in HTML5, which is the doctype I'm using.
I'm also wondering is there an easier way of doing this with jQuery?
Any help in saving my hairline would be GREATLY appreciated...

Nevermind, I'm a muppet.
It's got nothing to do with doctypes or Wordpress issues. Just my incorrect, sleep-deprived implementation of HTML.
This
<h2><a id="#test_link" class="internal"><?php the_title(); ?></a></h2>
should be
<h2><a id="test_link" class="internal"><?php the_title(); ?></a></h2>
Notice the missing "#" in the "ID" attribute, removing that makes everything work nicely :)

You don't need the separate a element...
http://www.yourhtmlsource.com/text/internallinks.html

Related

Wpml and Custom Widgets

In WPML some times custom widgets developed could not get translated.
Any string is translatable if the you copy paste the string then that string if searchable in WPML is translatable.
I have a website that has 4-5 Custom widgets + some hard coded part
For example there was a string in hard coded part-
Bet on your favorite sports online
I made it WPML compatible-
WPML version
N.B. Before posting the question here I have invested around 3-4 hours in understanding all the FAQ's at wpml.org site.
My problem-
I have various widgets, one such widgets has this portion-
<div class="signupoffers">
<div class="signupText"> <h2><?php echo $signup_text_title?></h2>
<p><?php echo $signup_text_content?></p><br>
</div>
<div class="signupbuttonDiv">
<div class="RegisterBlock">
<div class="block"><h2><?php echo $signup_btn_title?></h2>
<div>
<?php echo $signup_btn_content; ?>
</div>
</div>
</div>
<?php //nsu_signup_form();?>
</div>
</div>
Lets take an example this one-
I tried this http://screencast.com/t/3hJCPJgylXS
but the above one doesn't worked.
and various other versions, but no help so far.
Content here is coming dynamically from widget entry. May be I have some syntax issue. Does any one has encountered such situation before, Please guide me how to do that. Thanks!!
Let me ask the question in different way-
The string here is coming in a dynamic format-
<h2><?php echo $signup_btn_title?></h2>
How to convert it into wpml version so that wpml can read and search this string.
I tried this one, but it didn't worked-
<h2><?php _e('(<?php echo $seocontent_text_title;?>)','Casino'); ?></h2>
<h2><?php _e('(<?php echo $seocontent_text_title;?>)','Casino'); ?></h2>
this is definitely wrong
If any of similar approach, it should read similarly to this:
<?php _e( $seocontent_text_title, 'your_text_domain' ); ?>
You would probably also need to edit/create a wpml-config.xml file.
You could also try something along this lines:
(icl_translate function in strings)
<?php echo icl_translate(context, name, value); ?>">
I think this could help you to understand further:
https://wpml.org/forums/topic/transform-echo-to-php_e/
https://wpml.org/documentation/support/translation-for-texts-by-other-plugins-and-themes/
https://wpml.org/documentation/support/wpml-coding-api/

Anchor tag wont render correctly (WordPress PHP)

I am trying to add data atributes to my anchor tag for a WordPress custom theme.
The code below is what I've so far, the problem is with plain HTML this works fine but once I add the PHP lines then something breaks.
When the actual HTML is rendered it excludes the end of the open anchor tag, and leaves "> out to display on the page.
Not sure what went wrong but maybe someone can take a look at this and might be able to point out what I did wrong, a fix, a better way, or maybe if this is even possible.
<a
class="caption" href="<?php the_permalink()?>"
title="<?php the_title_attribute(); ?>"
data-title="<?php the_title(); ?>"
data-description="<?php the_excerpt(); ?>"
>
<?php the_post_thumbnail(array(301,301)); ?>
</a>
<?php endif; endif; ?>
This is not an answer, just some thoughts/things to try:
Are those PHP functions defined somewhere on the same page, or on a page that is included or required ?
Have you tried replacing those function calls with simple PHP commands, such as <?php echo "the_permalink_goes_here"; ?> etc. -- just to make sure, for example, that the anchor tag's href value changes to
<a href="the_permalink_goes_here" etc>
The excerpt function that you're using for the description is returning not just the excerpt, but also an additional "Read more" link, effectively putting an anchor inside your anchor tag, which is what is breaking it. To the best of my knowledge, there isn't a default WP function for returning an excerpt without this link, so you will need a function to do this. Try searching for 'excerpt without link'

CSS styling won't work on php function. (Wordpress)

I can't get CSS styling to work on content returned from a wordpress php function:
<span id="featured-excerpt"><?php the_excerpt(); ?></span>
The CSS style will work for anything before or after the php for excerpt, but the excerpt itself refuses to be styled. The only way I seem to have any success is where I try to place the php inside the span tag, which hardly seems correct, and creates a new single-space blank line after the php ouput....
<span id="featured-excerpt" <?php the_excerpt(); ?></span>
Any pointers would be appreciated.
In which case... Just looked at: http://codex.wordpress.org/Function_Reference/the_excerpt
It's entirely valid to:
<span id="featured-excerpt"><?php the_excerpt(); ?></span>
or
<div id="featured-excerpt"><?php the_excerpt(); ?></div>
EDIT (and given the comments):
Try removing the php function and render text, that way we'll know if this is a style or function issue:
<span id="featured-excerpt">Lord help us!</span>
How does it display? Does it display in your HTML output?
the_excerpt functions is returned with paragraph tags. The best easy solution is call the_content function instead of the_excerpt
the_content provide all css you add in content box.

Get post by its ID (WordPress)

How do I get a Custom Post by its ID in wordpress and show its thumbnail, title and content? Here is what I am using, but didnt the content is messed up.
<div class="left-cont1">
<div class="left-cont1-text">
<?php
query_posts('post_id=790&post_type=homepage');
while (have_posts()): the_post();
?>
<h1><?php the_title(); ?></h1>
<div class="cont1-border"></div>
<p><?php echo(types_render_field("homepage-content", array("raw"=>"true"))); ?></p>
<h2><?php echo(types_render_field("homepage-urltitle", array("raw"=>"true"))); ?></h2>
</div>
<div class="left-cont1-image1"><?php echo get_the_post_thumbnail($page->ID, 'home-circle'); ?></div>
<?php endwhile;?>
</div>
Thanks
You should be able to take your current code, change get_the_post_thumbnail($page->ID, 'home-circle') to get_the_post_thumbnail(get_the_id(), 'home-circle'), and replicate your code for each post you want to pull in, modifying the post_id=xxx to match the ID of the post you want to pull in.
This is not the most attractive solution, but from the information you gave, it should at least work. Just so you know, there is an entire StackExchange site devoted to Wordpress: https://wordpress.stackexchange.com/ where you should be able to get more Wordpress-specific answers. If your question is about PHP, please feel free to ask here, but if it is Wordpress-specific, your better bet would be the dedicated Wordpress site.
Since you're new to PHP, I would recommend getting an introductory book or two and try to get some of the basic concepts down pat before working with WordPress. While there will be a larger up-front investment of time, it will pay off in the long run. Good luck!

Using columns in Wordpress page that include header

I'm a little bit of a newb when it comes to PHP, but know enough to get around and would like to know if this can be done. sample
I want to break my wordpress page into 2 columns, but also want to have the header in the 1st column.... along with other text. I don't want the header floating over both columns...
The second column will house images only...
is that possible? In my head it makes sense, but then when I try and work it out, I'm just not sure....
And I just got thinking... I have my home page static with the smooth slider on it, so that is now going to cause more grief.
Any help, advice or pointers would be greatly appreciated.
Thanks in advance
This is more CSS/HTML than PHP, however that's fine. The first thing you need to do is understand how to make a two column layout. Then you will need to have the post title in the first column, something like this:
<article>
<div id="col1">
<h1>Post Title</h1>
Lorem ipsum dolor sit amet...
</div>
<div id="col2">
<img src="" />
</div>
</article>
To make this into WordPress you will of course need to add the WordPress Tags:
<div id="col1">
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
</div>
Finally, adding the image(s) on the right. It can be done easily using WordPress' built in functionality, if you only need one image: (Note you will have to add something in your theme's functions.php file as per the WordPress Docs)
<div id="col2">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
}
?>
</div>
To add multiple images, it gets more complex and you'll have to start looking for a plugin to achieve that goal.

Categories