Jump to content

how to insert a picture on the main page


Андрей
 Share

Recommended Posts

как вставить изображение на главную(родительскую) страницу с другой страницы(детской) можно использовать или только вызов происходит там где принадлежит поле

how to insert a picture on the main (parent) page from another page (child) can be used alone or where the call originates belongs to the field

test for example (child) page

<img src="<?=$page->images->first()->url ?>">

if($page->image) echo "<img src='{$page->test->image->url}'>";

Нужно вставить четыре изображения на главную(родитель)страницу изображения являются ссылками для(ребенок)

изображение должно указывать на (ребенок)и являться ссылка

как это сделать

Need to insert four images on the main (parent) page images are to (a child)

the image should point to (the child)and be a link

how to do it
Link to comment
Share on other sites

Hint.... :)

$PAGES IS YOUR CONNECTION TO ALL THE PAGES IN YOUR SITE

While the $page variable holds the current page, the $pages variable is where you can get at all the other pages in your site. It includes functions for getting, finding, saving and deleting pages. Each of these is documented below, following by several examples.

http://processwire.com/api/variables/pages/

Link to comment
Share on other sites

я не знаю PHP кроме функции <?php include("./includes/menu.php"); ?>

и функции DOM JQEERI  тоже темный лес, но хочется понять

I do not know  PHP except for the function <?php include("./includes/menu.php"); ?>

function and DOM JQEERI too dark forest,but I want to understand  :'(

Link to comment
Share on other sites

Off to bed...but this should give you another hint...

echo "<img src='". $pages->get(1419)->pictures->first()->url ."'>";//1419 = id of a child page (or any other page)

Just an example ;)

Edit: Oh, that page I linked to (the $pages docs); that has easy-enough PHP to get you going :)

Link to comment
Share on other sites

 <img src="/pw/site/assets/files/1006/tv_sat1.jpg" width="150" height="100" alt="" /> 

простым способом вставил указал в HEAD.inc  но это не правильно я так думаю, может я не прав это же CMS должна быть логика вывода полей в любом месте,просто я не могу правильно указать путь,потому что не знаю базовый  PHP 

The easiest way to put in HEAD.inc but this is not correct, I think it's CMS and MVC and HMVC be the logical conclusion of the field at any place, the right way, I do not know the true challenge of the field. The correct code. Thank you

<? echo "<img src='". $pages->get(1006)->pictures->first()->url ."'>";?>

<img src="<?=$page->get/tv(1006)->images->first()->url ?>">

<img src="<?=$page->tv->get(1006)->images->first()->url ?>">

<img src="<?=$page->get(1006)->tv->images->first()->url ?>">

такой способ не выводит данные

 this method does not take data

Link to comment
Share on other sites

Need to insert four images on the main (parent) page images are to (a child)

the image should point to (the child)and be a link

I'm not sure I understood completely your question, but i'll try to answer. My interpretation is that you have a page with four children, and you want a link to each of the children with a correspondent image taken from that children. This depends on how the limit from your image field. If the limit is "1" the field will return one image, and the url can be called with "$page->image->url". If the limit is different from one the field will return an array of images, and we would return the first image with "$page->images->first()->url" or "$page->images->eq(0)->url". I will assume the last case:

echo "<ul>";
// go through all children of this page
foreach ($page->children as $child) {
    echo "<li>";
    // print the url of the current child on the loop as the target of the anchor element
    echo "<a href='{$child->url}'>";
    // print the url of the first image on the current child as the source of the image element
    echo "<img src='{$child->images->first()->url}'>";
    echo "</a>";
    echo "</li>";
}
echo "</ul>";
  • Like 1
Link to comment
Share on other sites

ребенок  страница (tv) 

родитель страница (home) нужно здесь вставить изображение ребенок  страница (tv)

 

Child page (tv)

parent (home) page here to insert a picture the child page (tv)

<img src="<?=$page->get(1006)->tv->images->first()->url ?>">

<?echo "<img src='{$child->tv->images->first()->url}'>";?>


такой способ не выводит данные


 this method does not take data


Link to comment
Share on other sites

ребенок  страница (tv) 

родитель страница (home) нужно здесь вставить изображение ребенок  страница (tv)

 

Child page (tv)

parent (home) page here to insert a picture the child page (tv)

<img src="<?=$page->get(1006)->tv->images->first()->url ?>">

<?echo "<img src='{$child->tv->images->first()->url}'>";?>

такой способ не выводит данные

 this method does not take data

No it wont. Did you even read the docs I pointed to Andrei? Did you read Diogo's post above? 

$page->get(1006)->tv will not get you anything. First, $page always refers to the current page. Secondly, tv from what I can tell is a child page of home whose id is also 1006. I gave you code to insert first image of tv in home page in my example code.

OK, one last time...

Home (id = 1)

TV (id = 1006)

 

option 1: Get by page ID

echo "<img src='". $pages->get(1006)->images->first()->url ."'>";//images here is the name of the multiple image field

Option 2: Get by page name

echo "<img src='". $pages->get("/tv/")->images->first()->url ."'>";//images here is the name of the multiple image field

These are just examples...see Diogo's post how to get the link to the child page (tv)

Edited by kongondo
  • Like 2
Link to comment
Share on other sites

<div class="one_third">
                
                              <?php  echo "<img src='". $pages->get(1006)->images->first()->url ."'>";
                 echo "<img src='". $pages->get("/home/tv/")->images->first()->url ."'>"?>
                                
             </div
tv_sat1.jpg

Error: Call to a member function first() on a non-object (line 43 of C:\OpenServer\domains\localhost\pw\site\templates\head.inc)

This error message was shown because you are logged in as a Superuser. Error has been logged.

 

Работает но другие поля отключаются

Works but the other fields are disabled

я понял что лучше использовать страницы у которых свои поля  и создавать новые

вариант: 

1.создать четыре поля с изображением и ссылка и вставить в свой<div><?php echo $page->one_third; ?>

2.создать одно поле с таблицей и вставить четыре изображения в каждый <tr>

I realized that it is better to use the pages that their fields and create new option 
option
1. create four fields with an image and link and paste into your <div> <?php echo $page->one_third; ?>
2. Establish one field to the< table>and four<tr> and insert the four images in each <tr>
 
Link to comment
Share on other sites

Andrei,

1. There was an error in my code above which I corrected...the path to the page "tv" is: $pages->get("/tv/")

2. No need to create four image fields in the same page. If you want multiple images, use a multiple image field. Throw in the four images there. If you want to output all of them, see Diogo's code above...or below example..(this assumes you will only have four images)

$myimages = $pages->get("/tv/")->images;

foreach ($myimages as $myimage) {
	
   echo "<img src='{$myimage->url}'>";
	
}

That will output the four images...Place the code in your "home" template file...

Link to comment
Share on other sites

<div class="one_third">
                                  <?php  echo "<img src='". $pages->get(1006)->images->first()->url ."'>";
                                   echo "<img src='". $pages->get("/tv/")->images->first()->url ."'>"?>
                                
</div>
все работает
all works ideally
<div class="one_third">
                                      <?php  $myimages = $pages->get("/tv/")->images;
 
                                       foreach ($myimages as $myimage) {
    
                                       echo "<img src='{$myimage->url}'>";
    
}
?>
</div>
все работает
all works ideally

Спасибо и последний вопрос каждое изображение имеет название test.jpg где нужно вставить

Thanks and final question each image has a name where you want to insert test.jpg

<div class="one_third">
                                  <?php  echo "<img src='". $pages->get(1006)->images->first()->url ."'>";
                                   echo "<img src='". $pages->get("/tv/")->images->first()->url ."'>"?>
                                
</div>
Link to comment
Share on other sites

у страниц (ребёнок) будет свое  First () изображение 

и будет вставлено при смене параметра ('/tv/')

Спасибо очень помогли как мне так и другим

at pages (child) will have its First () image

will be inserted when you change a parameter ('/ TV /')
Thank you big been very helpful to me and to other  :rolleyes:
Link to comment
Share on other sites

СПАСИБО ВСЕМОГУЩИЙ KONGONDO

THANK THE ALMIGHTY KONGONDO

ещё одна просьба как вставить <a href  изображение как ссылка на  ("/tv/") страницу 

Another asked how to insert <a href image as a reference to ('/ tv /') page

<?php 
             echo "<img src='". $pages->get("/tv/")->images->first()->url ."'>"
?>
вроде того 
like that <a href='{$skyscraper->url}'>{$skyscraper->title}</a>
Link to comment
Share on other sites

In that case then, let's follow's Diogo's example. What we want to grab is the object (Page) for this child page "tv". With that, we have access to everything about it - all fields, etc. so:

$test = $pages->get("/tv/");//
echo "<p>The title of the child page with the images below is <a href='$test->url'>{$test->title}</a></p>";
foreach ($test->images as $image) {
 
echo "<img src='$image->url' alt=''/>";

}

As you can see, $test is giving us access to the attributes of "tv".

If you have more than one child page of home that you want to grab images from, no need to repeat the above code. In that case, follow Diogo's example above..

Edited by kongondo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...